From d47c2615ab2f0a411257ef3a6995cccf27b34768 Mon Sep 17 00:00:00 2001 From: Russell-S-Harper Date: Mon, 13 Aug 2018 08:49:48 -0400 Subject: [PATCH] Rounding of _SET_V result. --- common/common.h | 6 +++--- xa-pre-process/main.c | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) 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);