Patashu / break_eternity.js

A Javascript numerical library to represent numbers as large as 10^^1e308 and as small as 10^-10^^1e308. Sequel to break_infinity.js, designed for incremental games.
MIT License
120 stars 43 forks source link

`Decimal.ceil` is incorrect for very small positive numbers #130

Closed James103 closed 6 months ago

James103 commented 1 year ago

When Math.ceil is evaluated for a very small positive number, such as 1e-300, it returns 1, which is correct. When Decimal.ceil is evaluated for the same small positive number, it returns 0 which is incorrect and inconsistent with Math.ceil.

When Math.ceil is evaluated for a very small negative number, such as -1e-300, it returns -0, which is correct and equal to 0. When Decimal.ceil is evaluated for the same small negative number, it returns 0, which is correct.

Therefore, Decimal.ceil is incorrect for very small positive numbers, including but not limited to:

1e-16 // 1e-15 outputs the correct result of 1
1e-300
"1e-1000"
Decimal.recip("ee308")
Decimal.recip(Decimal.tetrate(10, Number.MAX_VALUE))

There is similar incorrect behavior for Decimal.floor with very small negative numbers:

Math.floor(-1e-300) == -1
Decimal.floor(-1e-300).toNumber() == 0 // Incorrect
Decimal.floor("-1e-1000").toNumber() == 0 // Incorrect
MathCookie17 commented 6 months ago

So far as I'm aware, this issue has been solved. All of the cases you have given now output the correct values.