better float idea

This commit is contained in:
pommicket 2022-01-12 09:59:34 -05:00
parent cbe3580001
commit 0d0455ce92
2 changed files with 18 additions and 14 deletions

View file

@ -68,7 +68,7 @@ function compile_warning
; ulong significand ; ulong significand
; ulong exponent ; ulong exponent
; where for i = -1023..1023, powers_of_10 + 16*i points to an entry where ; where for i = -1023..1023, powers_of_10 + 16*i points to an entry where
; (significand / 2^58) * 2^exponent ; 10^i = significand * 2^exponent
global powers_of_10 global powers_of_10
#include util.b #include util.b
@ -183,7 +183,7 @@ function fill_in_powers_of_10
powers_of_10 = malloc(40000) powers_of_10 = malloc(40000)
powers_of_10 += 20000 powers_of_10 += 20000
significand = 1 < 57 significand = 1 < 57
exponent = 1 exponent = -57
i = 0 i = 0
:pow10_loop_positive :pow10_loop_positive
p = powers_of_10 p = powers_of_10
@ -198,7 +198,7 @@ function fill_in_powers_of_10
i += 1 i += 1
if i < 1024 goto pow10_loop_positive if i < 1024 goto pow10_loop_positive
significand = 1 < 57 significand = 1 < 57
exponent = 1 exponent = -57
i = 0 i = 0
:pow10_loop_negative :pow10_loop_negative
p = powers_of_10 p = powers_of_10
@ -233,7 +233,6 @@ function print_powers_of_10
p = powers_of_10 p = powers_of_10
p += i < 4 p += i < 4
significand = *8p significand = *8p
putc('.)
j = 57 j = 57
:pow10_binary_loop :pow10_binary_loop
b = significand > j b = significand > j

View file

@ -283,12 +283,21 @@ function tokenize
; first, deal with the fractional part ; first, deal with the fractional part
p = powers_of_10 p = powers_of_10
p += pow10 < 4 p += pow10 < 4
full_multiply_signed(fraction, *8p, &upper, &lower) full_multiply_signed(fraction, *8p, &lower, &upper)
; effectively we want the upper 58 bits of this multiplication if upper == 0 goto fmultiply_no_upper
significand = lower > 58 n = leftmost_1bit(upper)
significand |= upper < 6 n += 1
significand = lower > n
exponent += n
n = 64 - n
significand |= upper < n
goto fmultiply_cont
:fmultiply_no_upper
significand = lower
goto fmultiply_cont
:fmultiply_cont
p += 8 p += 8
exponent = *8p exponent += *8p
putn(significand) putn(significand)
putc(32) putc(32)
@ -300,8 +309,7 @@ function tokenize
n += 1 n += 1
significand = right_shift(significand, n) significand = right_shift(significand, n)
exponent += n exponent += n
n = 58 - exponent significand += right_shift(integer, exponent)
significand += left_shift(integer, n)
putn(significand) putn(significand)
putc(32) putc(32)
putn_signed(exponent) putn_signed(exponent)
@ -320,9 +328,6 @@ function tokenize
significand &= ~b significand &= ~b
data = significand data = significand
exponent += 1023 ; float format exponent += 1023 ; float format
putc('*)
putn(exponent)
putc(10)
data |= exponent < 52 data |= exponent < 52