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
122 stars 46 forks source link

ssqrt returns 1 for too large numbers (layer ~ Number.MAX_SAFE_INTEGER). #30

Closed James103 closed 5 years ago

James103 commented 5 years ago

Expected result:

new Decimal.fromComponents(1,1000000000000000,10).ssqrt().toString()
"(e^999999999999998)10000000000"
new Decimal.fromComponents(1,10000000000000000,10).ssqrt().toString()
"(e^9999999999999998)10000000000"

Actual result:

new Decimal.fromComponents(1,1000000000000000,10).ssqrt().toString()
"(e^999999999999998)10000000000"
new Decimal.fromComponents(1,10000000000000000,10).ssqrt().toString()
"1"

Exact problem threshold point occurs when layer is around Number.MAX_SAFE_INTEGER.

Patashu commented 5 years ago

It looks like ssqrt for any number layer 3+ is just 'remove a layer' so I'll add this special case.