ref: 2551a75889ee7eee8d9cb222c9d4f3111fccfa85
parent: b0fd36e3db14286bc1408aacb8ff7273a85dd251
author: Ori Bernstein <[email protected]>
date: Sat Sep 9 21:35:47 EDT 2017
Fix 32 bit float formatting. It works now.
--- a/lib/std/fltbits.myr
+++ b/lib/std/fltbits.myr
@@ -48,12 +48,12 @@
bits = flt32bits(flt)
isneg = (bits >> 31) != 0 /* msb is sign bit */
- exp = (bits >> 22) & 0xff /* exp is in bits [23..30] */
- mant = bits & ((1 << 22) - 1) /* msb is in bits [0..22] */
+ exp = (bits >> 23) & 0xff /* exp is in bits [23..30] */
+ mant = bits & ((1 << 23) - 1) /* msb is in bits [0..22] */
/* add back the implicit bit if this is not a denormal */
if exp != 0
- mant |= 1 << 22
+ mant |= 1 << 23
else
exp = 1
;;
--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -32,7 +32,7 @@
var isneg, exp, mant
(isneg, mant, exp) = flt32explode(val)
- dragon4(sb, isneg, (mant : int64), (exp - 52 : int64), Fltbias, mode, precision)
+ dragon4(sb, isneg, (mant : int64), (exp - 23 : int64), Fltbias, mode, precision)
}
/*
--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -62,6 +62,7 @@
check("0x7b", "0x{x}", 123)
check("0.0", "{}", 0.0)
check("0.3", "{}", 0.3)
+ check("0.3", "{}", (0.3 : flt32))
check("1.0", "{}", 1.0)
check("100.0", "{}", 100.0)
check("666.91972", "{}", 666.91972)