summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-09-10 01:35:47 -0700
committerOri Bernstein <ori@eigenstate.org>2017-09-10 01:35:47 -0700
commit2551a75889ee7eee8d9cb222c9d4f3111fccfa85 (patch)
treee660cde138cce01d8e20b915d059cce878f8da11
parentb0fd36e3db14286bc1408aacb8ff7273a85dd251 (diff)
downloadmc-2551a75889ee7eee8d9cb222c9d4f3111fccfa85.tar.gz
Fix 32 bit float formatting.
It works now.
-rw-r--r--lib/std/fltbits.myr6
-rw-r--r--lib/std/fltfmt.myr2
-rw-r--r--lib/std/test/fmt.myr1
3 files changed, 5 insertions, 4 deletions
diff --git a/lib/std/fltbits.myr b/lib/std/fltbits.myr
index f9afd7a..0d7169b 100644
--- a/lib/std/fltbits.myr
+++ b/lib/std/fltbits.myr
@@ -48,12 +48,12 @@ const flt32explode = {flt
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
;;
diff --git a/lib/std/fltfmt.myr b/lib/std/fltfmt.myr
index 9bf627d..be67e64 100644
--- a/lib/std/fltfmt.myr
+++ b/lib/std/fltfmt.myr
@@ -32,7 +32,7 @@ const flt32bfmt = {sb, val, mode, precision
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)
}
/*
diff --git a/lib/std/test/fmt.myr b/lib/std/test/fmt.myr
index 67ba2e4..5d0cfa8 100644
--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -62,6 +62,7 @@ const builtins = {
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)