zipson icon indicating copy to clipboard operation
zipson copied to clipboard

handle exponential floats

Open zoryamba opened this issue 2 years ago • 4 comments

Fix for #15

Hope it won't affect performance significantly

zoryamba avatar Mar 01 '24 21:03 zoryamba

Good catch! However, I don't think we can regex evaluate all numbers to cover the scientific notation case. Is there another way to distinguish them?

There should be a cut-off where it is represented with those notions. However, I'm not sure that is platform agnostic. Regardless I think we'll have to find another approach for them as the regex at this very hot path is not really feasible I think.

jgranstrom avatar Mar 02 '24 09:03 jgranstrom

I haven't done any benchmarks, but i think it's valid concern...

According to this reference

All numbers in Javascript are 64bit (8 bytes) floating point numbers which yields an effective range of 5e-324 (negative) to 1.7976931348623157e+308 (positive) at the time this article was written (this may eventually change to 128 bits in the future as 64 bit processors become commonplace and the ECMA standards evolve).

JS numbers seems to be platform agnostic, but i wouldn't rely on internal Number implementation because it may change.

There is Number.prototype.toExponential method that seems to return the same result as toString for exponential numbers

So using something kinda if (Number.isInteger(obj) && obj.toString() !== obj.toExponential()) seems reasonable. I'll update the PR

zoryamba avatar Mar 03 '24 13:03 zoryamba

added few optimizations

zoryamba avatar Mar 03 '24 16:03 zoryamba

any more concerns here?

zoryamba avatar Mar 05 '24 23:03 zoryamba