1. cvr

Converts a number or string to a real number.

1.1. Syntax

num cvr → real
string cvr → real

1.2. Stack Effects

Table 1. Before
Level Object

0

num (integer or real) or string

Table 2. After
Level Object

0

real (real number result)

1.3. Description

cvr (convert to real) converts an integer, real, or string to a real number:

  • Integer operand: Converts to real

  • Real operand: Returns it unchanged

  • String operand: Parses as PostScript number, converts to real if integer

1.4. PostScript Level

Level 1 and later

1.5. Examples

Converting integer to real
42 cvr           % Result: 42.0
-17 cvr          % Result: -17.0
Real pass-through
3.14159 cvr      % Result: 3.14159 (unchanged)
String conversion
(123) cvr        % Result: 123.0
(3.14) cvr       % Result: 3.14
(1.5E2) cvr      % Result: 150.0

1.6. Common Use Cases

1.6.1. Ensuring Real Arithmetic

width cvr height cvr div  % Real division

1.6.2. Configuration Parsing

configfile readline {
  token { cvr /scale exch def } if
} if

1.7. Common Pitfalls

String Must Be Valid Number - String must contain valid PostScript number syntax.
(abc) cvr        % Error: syntaxerror
Use for Precision - Convert integers to reals before division to avoid integer truncation.

1.8. Error Conditions

Error Condition

[invalidaccess]

String has no-access attribute

[limitcheck]

Number exceeds implementation limits

[stackunderflow]

No operand on stack

[syntaxerror]

String not valid number syntax

[typecheck]

Operand not number or string

[undefinedresult]

Invalid number in string

1.9. See Also

  • cvi - Convert to integer

  • cvs - Convert to string

  • type - Get object type


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.