Fixed special convertion case from decimal 'x.y()' to fraction

This commit is contained in:
Celestino Amoroso 2024-05-15 06:45:40 +02:00
parent c9db4b84e3
commit aa1338cd51
2 changed files with 7 additions and 3 deletions

View File

@ -94,6 +94,9 @@ func makeGeneratingFraction(s string) (f *fraction, err error) {
} else if s[0] == '+' {
s = s[1:]
}
if strings.HasSuffix(s, "()") {
s = s[0 : len(s)-2]
}
parts = strings.SplitN(s, ".", 2)
if num, err = strconv.ParseInt(parts[0], 10, 64); err != nil {
return

View File

@ -158,6 +158,7 @@ func TestGeneralParser(t *testing.T) {
/* 137 */ {`builtin "os.file"`, int64(1), nil},
/* 138 */ {`v=10; v++; v`, int64(11), nil},
/* 139 */ {`1+1|2+0.5`, float64(2), nil},
/* 140 */ {`1.2()`, newFraction(6, 5), nil},
}
// t.Setenv("EXPR_PATH", ".")