Skip to content

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

@bbugh

Description

@bbugh
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions