]> gitweb.factorcode.org Git - factor.git/commitdiff
math.parser: fix edge case for float>dec
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 12 Feb 2024 16:35:20 +0000 (08:35 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 12 Feb 2024 16:35:20 +0000 (08:35 -0800)
0x1.5c17bbc13570bp-3 should print as 0.16996714290024104
but instead prints as 1.6996714290024104e-1

core/math/parser/parser-tests.factor
core/math/parser/parser.factor

index f7c86804c6be5202469ef7dc1244cbbdcb8799a4..9e3b3d2159047e90134880ba2ef5378905afd140 100644 (file)
@@ -514,6 +514,7 @@ unit-test
 { "143.99999999999997" } [ 0x1.1ffffffffffffp7 number>string ] unit-test
 { "144.0" } [ 0x1.2p7 number>string ] unit-test
 { "144.00000000000003" } [ 0x1.2000000000001p7 number>string ] unit-test
+{ "0.16996714290024104" } [ 0x1.5c17bbc13570bp-3 number>string ] unit-test
 
 { 0x80000000000000000000000000000000 } [ 0 φ ] unit-test
 
index e1754e4e07d8d430f91d8a806f72a9a86866ba46..2e1d5a4b0f4dd3447665859e70d5587088e8ecd5 100644 (file)
@@ -993,7 +993,7 @@ CONSTANT: lookup-table {
 
 : general-format ( s f e -- str )
     swap >dec [ length ] keep
-    2over swap [ + ] [ neg ] bi [ 1 max ] bi@ + 17 >
+    2over swap [ + ] [ neg ] bi [ 0 max ] [ 1 max ] bi* + 17 >
     [ exponential-format ] [ decimal-format ] if ; inline
 
 : float>dec ( n -- str )