@@ -70,8 +70,8 @@ local function read_base_param(base)
70
70
return base
71
71
end
72
72
73
- function fraction . from_float_string (
74
- str , -- < digit>{< digit>}.{ digit}[(< digit>{ digit}) ], ex.: `- 1.2(3)`
73
+ local function parse_positive_double_string (
74
+ str , -- EBNF: digit { digit } "." { digit } [ "(" digit { digit } ")" ], ex.: `1.2(3)`
75
75
base -- integer from 2 to 36, defaults to 10 (decimal)
76
76
)
77
77
base = read_base_param (base )
@@ -81,6 +81,7 @@ function fraction.from_float_string(
81
81
82
82
local integer , fractional = str :match (" ^([0-9a-zA-Z][0-9a-zA-Z]-)%.([0-9a-zA-Z%(%)]+)" )
83
83
if not fractional then
84
+ assert (str :match (" [0-9a-zA-Z]+" ))
84
85
return new (read_number (str ), 1 )
85
86
end
86
87
@@ -96,6 +97,16 @@ function fraction.from_float_string(
96
97
return read_number (integer ) + after_dot / base ^ # pre_period
97
98
end
98
99
100
+ function fraction .from_float_string (
101
+ str , -- EBNF: [ "-" ] digit { digit } "." { digit } [ "(" digit { digit } ")" ], ex.: `-1.2(3)`
102
+ base -- integer from 2 to 36, defaults to 10 (decimal)
103
+ )
104
+ if str :sub (1 , 1 ) == " -" then
105
+ return - parse_positive_double_string (str :sub (2 ), base )
106
+ end
107
+ return parse_positive_double_string (str , base )
108
+ end
109
+
99
110
-- Conversions
100
111
101
112
function metatable :__tostring ()
0 commit comments