summaryrefslogtreecommitdiff
path: root/05
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-01-12 09:45:20 -0500
committerpommicket <pommicket@gmail.com>2022-01-12 09:45:20 -0500
commitcbe358000183b0a66f719b93b52ba2ec292f8225 (patch)
tree6915d9705fa44409404f80738fcbe3e1a5d89b6e /05
parent0779a0fab511c1de6bf84d7b448f3f1bc0e213c2 (diff)
bad float implementation
Diffstat (limited to '05')
-rw-r--r--05/main.b1
-rw-r--r--05/tokenize.b25
-rw-r--r--05/util.b21
3 files changed, 41 insertions, 6 deletions
diff --git a/05/main.b b/05/main.b
index b247584..db2ed2d 100644
--- a/05/main.b
+++ b/05/main.b
@@ -88,6 +88,7 @@ function main
local tokens
fill_in_powers_of_10()
+ print_powers_of_10()
dat_banned_objmacros = 255
dat_banned_fmacros = 255
diff --git a/05/tokenize.b b/05/tokenize.b
index 5f87c71..850851f 100644
--- a/05/tokenize.b
+++ b/05/tokenize.b
@@ -288,18 +288,29 @@ function tokenize
significand = lower > 58
significand |= upper < 6
p += 8
- significand >= 0 - *8p
+ exponent = *8p
+
+ putn(significand)
+ putc(32)
+ putn_signed(exponent)
+ putc(10)
if integer == 0 goto float_no_integer
- ; we now have significand / 2^58 = fraction*10^pow10
; now deal with the integer part
- exponent = leftmost_1bit(integer)
- significand >= exponent
+ n = leftmost_1bit(integer)
+ n += 1
+ significand = right_shift(significand, n)
+ exponent += n
n = 58 - exponent
- significand += integer < n
+ significand += left_shift(integer, n)
+ 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
@@ -309,6 +320,10 @@ function tokenize
significand &= ~b
data = significand
exponent += 1023 ; float format
+ putc('*)
+ putn(exponent)
+ putc(10)
+
data |= exponent < 52
*1out = TOKEN_CONSTANT_FLOAT
diff --git a/05/util.b b/05/util.b
index fc1aa1e..138e440 100644
--- a/05/util.b
+++ b/05/util.b
@@ -24,7 +24,26 @@ function full_multiply_signed
*8p_lower = lower
*8p_upper = upper
return
-
+
+; allows for negative shifts
+function right_shift
+ argument x
+ argument n
+ if n < 0 goto right_shift_negative
+ return x > n
+ :right_shift_negative
+ n = 0 - n
+ return x < n
+
+; allows for negative shifts
+function left_shift
+ argument x
+ argument n
+ if n < 0 goto right_shift_negative
+ return x < n
+ :left_shift_negative
+ n = 0 - n
+ return x > n
function file_error
argument name