math.functions: make -0.3 truncate return 0.0 instead of -0.0.

modern-harvey2
John Benediktsson 2017-06-08 11:27:48 -07:00
parent 1dceb069ad
commit 57de1f5ab0
2 changed files with 5 additions and 3 deletions

View File

@ -159,7 +159,7 @@ CONSTANT: log10-factorial-1000 0x1.40f3593ed6f8ep11
{ -5.0 } [ -4.5 floor ] unit-test { -5.0 } [ -4.5 floor ] unit-test
{ -4.0 } [ -4.5 ceiling ] unit-test { -4.0 } [ -4.5 ceiling ] unit-test
{ t } [ -0.3 truncate double>bits -0.0 double>bits = ] unit-test { t } [ -0.3 truncate double>bits 0.0 double>bits = ] unit-test
{ t } [ -0.3 ceiling double>bits -0.0 double>bits = ] unit-test { t } [ -0.3 ceiling double>bits -0.0 double>bits = ] unit-test
{ t } [ 0.3 floor double>bits 0.0 double>bits = ] unit-test { t } [ 0.3 floor double>bits 0.0 double>bits = ] unit-test
{ t } [ 0.3 truncate double>bits 0.0 double>bits = ] unit-test { t } [ 0.3 truncate double>bits 0.0 double>bits = ] unit-test

View File

@ -360,8 +360,10 @@ M: float truncate
[ drop ] 2dip [ drop ] 2dip
dup 0 < [ dup 0 < [
! the float is between -1.0 and 1.0, ! the float is between -1.0 and 1.0,
! the result is +/-0.0 ! the result could be +/-0.0, but we will
drop -63 shift zero? 0.0 -0.0 ? ! return 0.0 instead similar to other
! languages
2drop 0.0 ! -63 shift zero? 0.0 -0.0 ?
] [ ] [
! Put zeroes in the correct part of the mantissa ! Put zeroes in the correct part of the mantissa
0x000fffffffffffff swap neg shift bitnot bitand 0x000fffffffffffff swap neg shift bitnot bitand