summaryrefslogtreecommitdiff
path: root/libstd
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-09-16 02:54:55 -0400
committerOri Bernstein <ori@eigenstate.org>2014-09-16 02:54:55 -0400
commitf744db6bbbfe7232448268f17a8d61200e45294c (patch)
tree891c89c4f9fb35bc890e40a5cfb6637b0d720606 /libstd
parent947a43ed69478be63f4d4437fa53f6162e8bbe40 (diff)
downloadmc-f744db6bbbfe7232448268f17a8d61200e45294c.tar.gz
Simplify the float explosion.
Don't try to adjust the biases/exponents. (I should probably try to fix the biases/exponents, or at least return the bias.)
Diffstat (limited to 'libstd')
-rw-r--r--libstd/floatbits.myr26
1 files changed, 13 insertions, 13 deletions
diff --git a/libstd/floatbits.myr b/libstd/floatbits.myr
index 991be48..d203072 100644
--- a/libstd/floatbits.myr
+++ b/libstd/floatbits.myr
@@ -1,14 +1,14 @@
pkg std =
- const float64bits : (flt : float64 -> uint64)
- const float32bits : (flt : float32 -> uint32)
+ const float64bits : (flt : float64 -> int64)
+ const float32bits : (flt : float32 -> int32)
const float64frombits : (bits : uint64 -> float64)
const float32frombits : (bits : uint32 -> float32)
- const float64explode : (flt : float64 -> (bool, uint64, int32))
- const float32explode : (flt : float64 -> (bool, uint64, int32))
+ const float64explode : (flt : float64 -> (bool, int64, int64))
+ const float32explode : (flt : float32 -> (bool, int32, int32))
;;
-const float64bits = {flt; -> (&flt castto(uint64#))#}
-const float32bits = {flt; -> (&flt castto(uint32#))#}
+const float64bits = {flt; -> (&flt castto(int64#))#}
+const float32bits = {flt; -> (&flt castto(int32#))#}
const float64frombits = {bits; -> (&bits castto(float64#))#}
const float32frombits = {bits; -> (&bits castto(float32#))#}
@@ -18,11 +18,11 @@ const float64explode = {flt
bits = float64bits(flt)
isneg = (bits >> 63) == 0 /* msb is sign bit */
exp = (bits >> 52) & 0x7ff /* exp is in bits [52..63] */
- mant = bits & ((1ul << 52) - 1) /* msb is in bits [..51] */
+ mant = bits & ((1l << 52) - 1) /* msb is in bits [..51] */
/* add back the implicit bit if this is not a denormal */
if exp != 0
- mant |= 1ul << 52
+ mant |= 1l << 52
else
exp = 1
;;
@@ -32,20 +32,20 @@ const float64explode = {flt
our exponent bias needs to be offset by the
size of m
*/
- -> (isneg, mant, (exp castto(int32)) - 1075)
+ -> (isneg, mant, exp)
}
const float32explode = {flt
var bits, isneg, mant, exp
- bits = float64bits(flt) castto(uint64)
+ bits = float32bits(flt)
isneg = (bits >> 31) == 0 /* msb is sign bit */
exp = (bits >> 22) & 0xff /* exp is in bits [23..30] */
- mant = bits & ((1ul << 52) - 1) /* msb is in bits [0..22] */
+ mant = bits & ((1 << 22) - 1) /* msb is in bits [0..22] */
/* add back the implicit bit if this is not a denormal */
if exp != 0
- mant |= 1ul << 22
+ mant |= 1 << 22
else
exp = 1
;;
@@ -55,6 +55,6 @@ const float32explode = {flt
our exponent bias needs to be offset by the
size of m
*/
- -> (isneg, mant, (exp castto(int32)) - 149)
+ -> (isneg, mant, exp)
}