diff --git a/common/common.h b/common/common.h index 08e464e..c98b000 100644 --- a/common/common.h +++ b/common/common.h @@ -6,10 +6,10 @@ ; to be able to recognize an overflow/underflow situation, rescale the arguments, and repeat the ; calculation. -; Largest value: $3fffffff or 1048575.999(9) -; Smallest value: $c0000001 or -1048575.999(0) +; Largest value: $3fffffff or 1048575.999(5) +; Smallest value: $c0000001 or -1048575.998(5) <- note 998(5) ; Largest value for DEC/HEX: $3d08ffff or 999999.999(5) -; Smallest value for DEC/HEX: $c2f70001 or -999999.999(0) +; Smallest value for DEC/HEX: $c2f70000 or -999999.999(5) ; Instructions diff --git a/xa-pre-process/main.c b/xa-pre-process/main.c index 7e2609b..ad4d7e8 100644 --- a/xa-pre-process/main.c +++ b/xa-pre-process/main.c @@ -23,7 +23,7 @@ int main(int argc, char **argv) int i; for (i = 0; i < count; ++i) { - int j; + int j, sign; unsigned long working; const char *s = "", *p, *q; switch (tokens[i].type) @@ -37,8 +37,14 @@ int main(int argc, char **argv) yyin = fmemopen((void *)p, q - p, "r"); yyparse(); fclose(yyin); - /* Output */ + /* Round towards ± infinity */ + sign = result < 0? -1: +1; + if (sign < 0) result = -result; + result += 1 << (INT_FRAC - EXP_FRAC - 1); + if (sign < 0) result = -result; + /* Normalize */ working = (unsigned long)((result >> (INT_FRAC - EXP_FRAC)) % (1 << EXP_FULL)); + /* Output in .BYTE format */ for (j = 0; j < EXP_FULL; j += CHAR_BIT) { printf("%s$%02lX", s, working & 0xff);