oops, float>hex didn't preserve leading zeroes in mantissa

db4
Joe Groff 2009-09-20 16:48:42 -05:00
parent 29c4512066
commit f459c24e45
2 changed files with 5 additions and 1 deletions

View 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

View 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 ;