Some code:
INTEGER_TEST: PROGRAM;
DECLARE INTEGER, X, Y, Z, T INITIAL(32767), U, V, W;
DECLARE INTEGER DOUBLE, X2, Y2, Z2, T2 INITIAL(2147483647), U2, V2, W2;
X = 8.7654321;
X2 = 8.7654321;
Y = 1.2345678;
Y2 = 1.2345678;
Z = X Y;
Z2 = X2 Y2;
U = T**2;
U2 = T2 T2;
V = T**3;
V2 = T2**3;
W = T**4;
W2 = T2 T2 T2 T2;
WRITE(6) X, ' ', Y, ' ', Z, ' ', T, ' ', U, ' ', V, ' ', W;
WRITE(6) X2, ' ', Y2, ' ', Z2, ' ', T2, ' ', U2, ' ', V2, ' ', W2;
WRITE(6) X-X2, ' ', Y-Y2, ' ', Z-Z2, ' ', T-T2, ' ', U-U2, ' ', V-V2, ' ',
W-W2;
CLOSE INTEGER_TEST;
Running it in yaHALMAT:
8 1 8 32767 1073676289 1073840127 2147352577
8 1 8 2147483392 65536 -16777216 0
0 0 0 -2147450625 1073610753 1090617343 2147352577
Some observations:
First, INTEGER DOUBLE is treated exactly like INTEGER, which is wrong. Should be 64-bit32-bit 2's-complement vs 32-bit16-bit 2's-complement. [Embarrassing! All this time I thought it was 64-bit vs 32-bit. ☹️ One implication is that I was wrong in saying INTEGER should always be printed 11 characters wide. INTEGER should be 6 characters wide, while INTEGER DOUBLE should be 11 characters wide.]
Second, in an assignment like X = 8.7654321, the floating-point value has been truncated to 8 when assigned to an integer variable. This is wrong. Both the HAL/S Language Specification and Ryer say it must be rounded. According to Ryer p. 3-4:
Third, not a complaint but a question: I notice that for arithmetical overflow in an integer operation like a multiplication, you pin the result at the maximum INTEGER value rather than wrapping around like (for example) C would. Is this a decision on your part, or did you read someplace that that's supposed to be the actual behavior in HAL/S? I myself can't find any statement in the documentation one way or the other. There are arguments to be made for either approach, but of course we need to do it the way Intermetrics did, even if it happened to be the crummiest approach in our opinion(s). 😄
Some code:
INTEGER_TEST: PROGRAM; DECLARE INTEGER, X, Y, Z, T INITIAL(32767), U, V, W; DECLARE INTEGER DOUBLE, X2, Y2, Z2, T2 INITIAL(2147483647), U2, V2, W2; X = 8.7654321; X2 = 8.7654321; Y = 1.2345678; Y2 = 1.2345678; Z = X Y; Z2 = X2 Y2; U = T**2; U2 = T2 T2; V = T**3; V2 = T2**3; W = T**4; W2 = T2 T2 T2 T2; WRITE(6) X, ' ', Y, ' ', Z, ' ', T, ' ', U, ' ', V, ' ', W; WRITE(6) X2, ' ', Y2, ' ', Z2, ' ', T2, ' ', U2, ' ', V2, ' ', W2; WRITE(6) X-X2, ' ', Y-Y2, ' ', Z-Z2, ' ', T-T2, ' ', U-U2, ' ', V-V2, ' ', W-W2; CLOSE INTEGER_TEST;Running it in yaHALMAT:
8 1 8 32767 1073676289 1073840127 2147352577 8 1 8 2147483392 65536 -16777216 0 0 0 0 -2147450625 1073610753 1090617343 2147352577Some observations:
First, INTEGER DOUBLE is treated exactly like INTEGER, which is wrong. Should be☹️ One implication is that I was wrong in saying INTEGER should always be printed 11 characters wide. INTEGER should be 6 characters wide, while INTEGER DOUBLE should be 11 characters wide.]
64-bit32-bit 2's-complement vs32-bit16-bit 2's-complement. [Embarrassing! All this time I thought it was 64-bit vs 32-bit.Second, in an assignment like X = 8.7654321, the floating-point value has been truncated to 8 when assigned to an integer variable. This is wrong. Both the HAL/S Language Specification and Ryer say it must be rounded. According to Ryer p. 3-4:
Third, not a complaint but a question: I notice that for arithmetical overflow in an integer operation like a multiplication, you pin the result at the maximum INTEGER value rather than wrapping around like (for example) C would. Is this a decision on your part, or did you read someplace that that's supposed to be the actual behavior in HAL/S? I myself can't find any statement in the documentation one way or the other. There are arguments to be made for either approach, but of course we need to do it the way Intermetrics did, even if it happened to be the crummiest approach in our opinion(s). 😄