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

The normalization of `new Decimal(-Infinity)` breaks some operations and may be incorrect #168

Closed James103 closed 3 months ago

James103 commented 4 months ago

new Decimal(Infinity) returns a Decimal object with { sign: 1, mag: Infinity, layer: Infinity }. new Decimal(Infintiy).negate() returns a Decimal object with { sign: -1, mag: Infinity, layer: Infinity }. Normalizing this with new Decimal(Infintiy).negate().normalize(), I get a Decimal object with { sign: -1, mag: -Infinity, layer: -Infinity }. Running new Decimal(-Infinity) directly also returns a Decimal object with { sign: -1, mag: -Infinity, layer: -Infinity }.

Either the normalization of new Decimal(-Infinity) should be a Decimal object with { sign: -1, mag: Infinity, layer: Infinity }, or functions operating on Decimals should be changed to handle Decimals consisting of { sign: -1, mag: -Infinity, layer: -Infinity }.

Originally found in https://mathcookie17.github.io/Eternal-Notations/, by navigating to that page, opening a browser console for that page, and running the command formatAll(new Decimal(-Infinity)) there.

MathCookie17 commented 3 months ago

I am of the opinion that -Infinity should be {-1, Infinity, Infinity}, but break_eternity was designed with -Infinity as {-1, -Infinity, -Infinity}, so that's what it normalizes to - it just wasn't even registering as -Infinity as all when I had it normalizing to {-1, Infinity, Infinity}. I don't want to cause a breaking change, so despite my preferences, it'll remain as {-1, -Infinity, -Infinity}... so I'll probably need to make a bunch of special cases to fix it in the functions. I'll look into this at some point.

MathCookie17 commented 3 months ago

I did an immediate fix for the Eternal Notations issue (i.e. it now detects infinities in a way that sidesteps the break_eternity bug, so -Infinity works there now. Figured I'd note this here since this was kind of an Eternal Notations issue too, though I haven't looked at the actual break_eternity bug yet)

MathCookie17 commented 3 months ago

...on second thought, there are just too many strange cases that {-1, -Infinity, -Infinity} causes. I'm changing it to {-1, Infinity, Infinity} like it always should have been.