]> gitweb.factorcode.org Git - factor.git/commitdiff
oops, float>hex didn't preserve leading zeroes in mantissa
authorJoe Groff <arcata@gmail.com>
Sun, 20 Sep 2009 21:48:42 +0000 (16:48 -0500)
committerJoe Groff <arcata@gmail.com>
Sun, 20 Sep 2009 21:48:42 +0000 (16:48 -0500)
core/math/parser/parser-tests.factor
core/math/parser/parser.factor

index f2ccb78a06fbbe81e5ea8be6d17001a43d375ab3..34bca8a34eae4b6a3f70cb8624b901ab67c0f2f2 100644 (file)
@@ -129,6 +129,7 @@ unit-test
 
 [ "1.0p0" ] [ 1.0 >hex ] unit-test
 [ "1.8p2" ] [ 6.0 >hex ] unit-test
+[ "1.08p2" ] [ 4.125 >hex ] unit-test
 [ "1.8p-2" ] [ 0.375 >hex ] unit-test
 [ "-1.8p2" ] [ -6.0 >hex ] unit-test
 [ "1.8p10" ] [ 1536.0 >hex ] unit-test
@@ -137,6 +138,8 @@ unit-test
 [ "-0.0" ] [ -0.0 >hex ] unit-test
 
 [ 1.0 ] [ "1.0" hex> ] unit-test
+[ 1.5 ] [ "1.8" hex> ] unit-test
+[ 1.03125 ] [ "1.08" hex> ] unit-test
 [ 15.5 ] [ "f.8" hex> ] unit-test
 [ 15.53125 ] [ "f.88" hex> ] unit-test
 [ -15.5 ] [ "-f.8" hex> ] unit-test
index d422a2c1999d07b609a195fb060072af846a51e0..a53604ddf92fbfb6947a5aacf46d076110de615f 100644 (file)
@@ -213,7 +213,8 @@ M: ratio >base
     -0.0 double>bits bitand zero? "" "-" ? ;
 
 : float>hex-value ( mantissa -- str )
-    16 >base [ CHAR: 0 = ] trim-tail [ "0" ] [ ] if-empty "1." prepend ;
+    16 >base 13 CHAR: 0 pad-head [ CHAR: 0 = ] trim-tail
+    [ "0" ] [ ] if-empty "1." prepend ;
 
 : float>hex-expt ( mantissa -- str )
     10 >base "p" prepend ;