The internal representation of Boolean, integer, dinteger, and both normalized and nonnormalized complex, double, and real values are all different. You must take care while coercing a value from one type to another. Certain system software, such as intrinsics and operating system procedures, expect input parameters to be in a particular format, and if the expected bit pattern of a variable has been altered through type coercion, this software will not work correctly.
Type coercion can be effected through the following:
-
Address equation between Boolean, integer, and real variables.
-
Address equation between dinteger, double, and complex variables.
-
Using a type transfer variable on the left side of an arithmetic or Boolean assignment.
-
Using a type-transfer function such as the INTEGER function.
-
Using a call-by-name parameter (for example, by passing a real variable to a call-by-name integer parameter).
The following is an example of address equation:
BEGIN
BOOLEAN B;
INTEGER I = B;
REAL R = B;
B := TRUE; % B = TRUE
% I = 1
% R =1.0
B := NOT TRUE; % B = FALSE
% I = Invalid or 0,
% R = (-7.0064 E-46)
I := 3; % B = TRUE,
% I = 3
% R = 3.0
R := 3; % B = TRUE
% I = 3
% R = 3.0
R := 3.0; % B = FALSE
% I = Invalid, 2.0E37, or 3
% R = 3.0
I := 4/3; % B = TRUE
% I = 1
% R = 1.0
I := I & (1) [47:1]; % B = TRUE & (TRUE) [47:1]
% I = 1 & (1) [47:1]
% R = 1.0 & (1) [47:1]
R := 1; % NOTE: This is setup for the following statement,
% which requires a type coercion of the value
% on the right side of the assignment. This
% coercion consists of an integerization, which
% may or may not preserve the value of bit 47. Thus:
I := R & (1) [47:1]; % B = TRUE & (indeterminate) [47:1]
% I = 1 & (indeterminate) [47:1]
% R = 1.0 & (indeterminate) [47:1]
R := 1; % NOTE: This is setup for the following statement,
% in which no type coercion is involved and in which
% the value of bit 47 is preserved. Thus:
R := R & (1) [47:1]; % B = TRUE & (TRUE) [47:1]
% I = 1 & (1) [47:1]
% R = 1.0 & (1) [47:1]
I := 1; % Note: This is setup for the following statement,
% which likewise requires a type coercion of the value
% (in this case, that coercion is explicit). But
% coercion to type Boolean preserves all bits in the
% source argument. Thus:
B := BOOLEAN (1 & 1 [47:1]);
% B = TRUE & (TRUE) [47:1]
% I = 1 & (1) [47:1]
% R = 1.0 & (1) [47:1]
END.
