formatting: fix exception when formatting the integer 0 using "%e"

modern-harvey2
Jon Harper 2017-07-06 23:36:29 +02:00 committed by Björn Lindqvist
parent 8675cb2c25
commit 7c2e964fc9
2 changed files with 2 additions and 1 deletions

View File

@ -36,6 +36,7 @@ IN: formatting.tests
{ "1.4" } [ 135/100 "%.1f" sprintf ] unit-test
{ "4" } [ 7/2 "%.0f" sprintf ] unit-test
{ "1" } [ 1.0 "%.0f" sprintf ] unit-test
{ "0.0e+00" } [ 0 "%.1e" sprintf ] unit-test
{ " 1.23" } [ 1.23456789 "%6.2f" sprintf ] unit-test
{ "001100" } [ 12 "%06b" sprintf ] unit-test
{ "==14" } [ 12 "%'=4o" sprintf ] unit-test

View File

@ -61,7 +61,7 @@ IN: formatting
: format-fast-scientific? ( x digits -- x' digits ? )
over float? [ t ]
[ 2dup
[ abs integer-log10 abs 308 < ]
[ [ t ] [ abs integer-log10 abs 308 < ] if-zero ]
[ 15 < ] bi* and
[ [ [ >float ] dip ] when ] keep
] if ;