feat: add Num.fromString static method to parse decimal string literals
Implements a new `fromString` static method on the `Num` class that attempts to parse a string as a decimal number literal using `strtod`. Returns the parsed `Num` value on success, or `null` if the string does not represent a valid number. Includes runtime validation that the argument is a string, and adds test coverage for positive, negative, zero, and decimal inputs as well as non-numeric strings.
This commit is contained in:
@@ -90,3 +90,10 @@ It is a runtime error if `other` is not a number.
|
||||
### **...**(other) operator
|
||||
|
||||
**TODO**
|
||||
|
||||
### Num.**fromString**(value)
|
||||
|
||||
Attempts to parse `value` as a decimal literal and return it as an instance of
|
||||
`Num`. If the number cannot be parsed `null` will be returned.
|
||||
|
||||
It is a runtime error if `value` is not a string.
|
||||
Reference in New Issue
Block a user