Table of Contents
1. cvr
Converts a number or string to a real number.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
0 |
|
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.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.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 |
|---|---|
[ |
String has no-access attribute |
[ |
Number exceeds implementation limits |
[ |
No operand on stack |
[ |
String not valid number syntax |
[ |
Operand not number or string |
[ |
Invalid number in string |