ContentsIndexPreviousNext

2.1.2.1 Numeric literals

A numeric literal is a character string selected from the digits, the plus sign, the minus sign, and the decimal point. Numeric literals may contain up to 18 digits. The following rules govern the formation of numeric literals.

1. A literal must contain at least one digit.

2. It must contain no more than one sign character and, if one is used, it must be the leftmost character of the string.

3. A literal must not contain more than one decimal point. The decimal point is treated as an assumed decimal point and may appear anywhere within the literal except as the rightmost character.

If a literal conforms to the rules for formation of a numeric literal, but is enclosed in quotation marks, it is a nonnumeric literal.

Numeric literals may also be specified using binary, octal, or hexadecimal notation. To specify a numeric literal in one of these forms, preface the number with one of the following prefixes:

Binary
"B#"
Octal
"O#"
Hexadecimal
"X#" or "H#"

For example:

Number
Binary
Octal
Hexadecimal
3
B#11
O#3
X#3 or H#3
8
B#1000
O#10
X#8 or H#8
12
B#1100
O#14
X#C or H#C
128
B#10000000
O#200
X#80 or H#80
255
B#11111111
O#377
X#FF or H#FF

Leading zeroes after the "#" are ignored. For example, X#00FF and X#FF are equivalent.

The compiler converts each numeric literal specified in this way to an unsigned long integer. In most cases, this is a 32-bit unsigned number, so the maximum value of a numeric literal that can specified with this notation is 4294967295, or (2**32) -1.

"LENGTH OF" expression

The "LENGTH OF" expression can be used anywhere you would use a numeric literal, except as a subscript or reference modifier. The compiler treats this expression as if you have coded a numeric literal. The "LENGTH OF" expression is written as follows:

LENGTH OF data-name

Data-name can be a numeric or nonnumeric literal or the name of a data item of any type. The compiler calculates the value of the "LENGTH OF" expression and replaces it with a numeric literal equivalent to the current number of bytes of storage used by the data item or literal referenced in "LENGTH OF." For example:

77 my-item PIC x(10).
78 my-item-length value LENGTH OF my-item.

becomes:

77 my-item PIC x(10).
78 my-item-length value 10.

Floating Point Literals

1. A floating point literal has the following format:

[  +  ]  k.m  {  E  }  [  +  ]  n
[  -  ]       {  e  }  [  -  ]

In the above:

Here are a few examples of floating point numbers:

-12.345e12
.0123E-6
123.E1

2. Floating-point literals in the Procedure Division are stored internally as USAGE DOUBLE.

3. The legal range of floating-point values is determined by the target machine. If you express a literal that is out of range for a particular machine, the runtime reports a warning message and substitutes the closest boundary value--either zero or the maximum floating-point value for the machine.

4. On some computers, floating point computations may give imprecise results. This is a hardware limitation, some floating point numbers cannot be precisely represented on some machines.