ExpantaNum.js
ExpantaNum.js copied to clipboard
fromString() (or fromHyperE()?) don't parse larger string numbers
ExpantaNum.fromString("1.000F10")
// Malformed input: 1.000F10
ExpantaNum.HyperE("1.000F10")
// Malformed input: 1.000F10
Seems like this line:
https://github.com/Naruyoko/ExpantaNum.js/blob/49b1fc5ff36c4f8cb4ac633e51d6a6cf4ce4c573/ExpantaNum.js#L42
needs to include [E-Ze]+ (or whatever the max range is):
- isExpantaNum = /^[-\+]*(Infinity|NaN|(J+|J\^\d+ )?(10(\^+|\{[1-9]\d*\})|\(10(\^+|\{[1-9]\d*\})\)\^[1-9]\d* )*((\d+(\.\d*)?|\d*\.\d+)?([Ee][-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/,
+ isExpantaNum = /^[-\+]*(Infinity|NaN|(J+|J\^\d+ )?(10(\^+|\{[1-9]\d*\})|\(10(\^+|\{[1-9]\d*\})\)\^[1-9]\d* )*((\d+(\.\d*)?|\d*\.\d+)?([E-Ze]+[-\+]*))*(0|\d+(\.\d*)?|\d*\.\d+))$/,
^^^^^^^
And it seems like that works now:
isExpantaNum.test("1.000e10")
// true
isExpantaNum.test("1.000e10e25")
// true
isExpantaNum.test("1.000F10")
// true
isExpantaNum.test("Ge1.025e52")
// true
isExpantaNum.test("1.00FF125")
// true
isExpantaNum.test("1.00A125e25")
// false
However, it doesn't parse the strings correctly still, just doesn't say it's malformed input.
fromHyperE looks to use a similar regex, but not isExpantaNum, I'm not sure what that's for.
I created a PR with jest tests to demonstrate the issue: https://github.com/Naruyoko/ExpantaNum.js/pull/24
This is probably more a missing feature since I don't remember implementing it. I could consider adding the support when I refactor the parsing code in the future.