Patashu / break_infinity.js

A replacement for decimal.js for incremental games who want to deal with very large numbers (bigger in magnitude than 1e308, up to as much as 1e(9e15) ) and want to prioritize speed over accuracy.
MIT License
201 stars 35 forks source link

new Decimal('Infinity') returns error from v.2.1.0. #152

Closed gusmachine closed 1 year ago

gusmachine commented 1 year ago

Environment: OS: Debian GNU/Linux bookworm Google Chrome 111.0.5563.41 (Official Build) beta (64-bit)

Steps to repro:

  1. Open url: data:text/html,<script src="https://unpkg.com/break_infinity.js/dist/break_infinity.min.js"></script>
  2. Type new Decimal('Infinity'); in the developer console.

Expected: The Infinity decimal is defined.

Actual: An error is thrown.

break_infinity.min.js:1 Uncaught Error: [DecimalError] Invalid argument: infinity
    at s.fromString (break_infinity.min.js:1:3124)
    at new s (break_infinity.min.js:1:1870)
    at <anonymous>:1:1

The error is thrown from here. https://github.com/Patashu/break_infinity.js/blob/89761e1742cf87193eab6414208b051f68603307/src/decimal.ts#L199

Observations:

I believe this is caused by the tolower placed here. parseFloat('Infinity') is Infinity while parseFloat('infinity') is NaN. This parseFloat was added on v.2.1.0. There were no towloer in v.2.0.0 https://github.com/Patashu/break_infinity.js/blob/89761e1742cf87193eab6414208b051f68603307/src/decimal.ts#L182

I'm reporting this because some other software is broken by this change, namely https://github.com/kaz-mighty/newincrementalgame-simulator/blob/f59042c0740b9f5dd0dd7e433cde079aee688e4c/nig_sim.js#L1735 . This worked fine yesterday.

Razenpok commented 1 year ago

Yes, it looks like v2.1.0 and v2.1.1 are not working correctly if you rely on Infinity or NaN. I'll publish a v2.2.0 that reverts the changes from v2.1.0 and v2.1.1.