Merge pull request #10 from Russell-S-Harper/development

Rounding of _SET_V result.
This commit is contained in:
Russell-S-Harper 2018-08-13 08:51:27 -04:00 committed by GitHub
commit a65e826f02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -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

View File

@ -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);