Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fromString() (or fromHyperE()?) don't parse larger string numbers #23

Open
bbugh opened this issue Feb 26, 2023 · 1 comment
Open

fromString() (or fromHyperE()?) don't parse larger string numbers #23

bbugh opened this issue Feb 26, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@bbugh
Copy link

bbugh commented Feb 26, 2023

ExpantaNum.fromString("1.000F10")
// Malformed input: 1.000F10

ExpantaNum.HyperE("1.000F10")
// Malformed input: 1.000F10

Seems like this line:

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+))$/,

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: #24

@Naruyoko
Copy link
Owner

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.

@Naruyoko Naruyoko added the enhancement New feature or request label Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants