HP Pascal/iX Programmer's Guide (31502-90023)

4: 4
b := bit32(i) + 1; { zero is stored }
b := bit32(hex('ffffffff'));
$pop$
try
i := b; { run-time error }
recover ;
try
i := b + i; { b and i are converted to longint and are }
{ too big to fit back into i }
recover ;
i := hex('ffffffff'); { both b and i now have all bits on }
{ the following never prints since i is sign extended to longint and
b is zero extended to longint }
if i = b then writeln('equal');
end.
Bit52
The predefined data type
bit52
is a subrange, 0..252-1, that is stored in
64 bits.
bit52
is a unique HP Pascal type because arithmetic operations
on
bit52
data are performed as unsigned 64-bit integers. Unsigned
addition and subtraction do not overflow.[REV BEG] Unsigned multiply may
overflow. The compiler option OVFLCHECK has no effect.
Note that there are no
bit52
constants in the compiler. Therefore,
numbers in the range maxint + 1..252 -1 can not be expressed directly.
The function hex can be used with the compiler options TYPE_COERCION and
RANGE to fill part of this range.[REV END] The compiler option
TYPE_COERCION is also needed when initializing a
bit52
constant field.
In this case, bit52() is not used. When
bit52
is used in an executable
statement, RANGE OFF must be used.
For number in the range of 232..252-1, a run-time computation must be
done. If the numbers are all constants, they must be type coerced to
bit52
so they do not integer overflow.
Variant records can also be used to build up these large constants.
To determine if a type T is assignment compatible with
bit52
.
* If variable v is of type T and variable b52 is of type
bit52
, then
the assignment b52 := v is legal if the value of v is within the
range 0..252-1.
* If the ranges of T and
bit52
do not overlap, the assignment b52 :=
v causes a compile-time error.
* If the ranges of T and
bit52
do overlap, but the value of v is
outside the range of
bit52
, then the assignment b52 := v causes a
run-time error.
Example
$standard_level 'hp_modcal'$
program prog_bit52(output);
var i : integer;
b : bit52;
type rec = record
f1 : bit52;
end;
$push; type_coercion 'conversion'$