diff options
author | pommicket <pommicket@gmail.com> | 2022-01-12 12:54:06 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-01-12 12:54:06 -0500 |
commit | f17720731d616c8b603ef4e853c69a2979f73604 (patch) | |
tree | 2efccda772297fa59e2e7909d8ac1659618be778 | |
parent | 0d0455ce9232bdaafad0823967efa98f0431f141 (diff) |
"nice" floating-point literals seem to work
-rw-r--r-- | 05/main.b | 1 | ||||
-rw-r--r-- | 05/main.c | 2 | ||||
-rw-r--r-- | 05/tokenize.b | 24 |
3 files changed, 14 insertions, 13 deletions
@@ -88,7 +88,6 @@ function main local tokens fill_in_powers_of_10() - print_powers_of_10() dat_banned_objmacros = 255 dat_banned_fmacros = 255 @@ -2,4 +2,4 @@ char * = "How are you"" d""o""i""ng today?\n"; hi _TEST _ING _1 -4.2 +1.00001 diff --git a/05/tokenize.b b/05/tokenize.b index 4ad858b..ff70ca3 100644 --- a/05/tokenize.b +++ b/05/tokenize.b @@ -122,6 +122,7 @@ function tokenize local data local significand local exponent + local new_exponent local pow10 local integer local fraction @@ -305,24 +306,25 @@ function tokenize putc(10) if integer == 0 goto float_no_integer ; now deal with the integer part - n = leftmost_1bit(integer) - n += 1 + new_exponent = leftmost_1bit(integer) + new_exponent -= 58 + n = new_exponent - exponent significand = right_shift(significand, n) - exponent += n + exponent = new_exponent significand += right_shift(integer, exponent) - putn(significand) - putc(32) - putn_signed(exponent) - putc(10) if *1in != 'e goto float_no_exponent :float_no_exponent if significand == 0 goto float_zero normalize_float(&significand, &exponent) - ; reduce to 52-bit significant - significand >= 6 - exponent += 6 - exponent += 51 ; 1001010111... => 1.001010111... + putn(significand) + putc(32) + putn_signed(exponent) + putc(10) + ; reduce to 53-bit significant (top bit is removed to get 52) + significand >= 5 + exponent += 5 + exponent += 52 ; 1001010111... => 1.001010111... n = leftmost_1bit(significand) b = 1 < n significand &= ~b |