diff --git a/_lua5.1-tests/math.lua b/_lua5.1-tests/math.lua index 21429a6f..f82ed6c1 100644 --- a/_lua5.1-tests/math.lua +++ b/_lua5.1-tests/math.lua @@ -52,6 +52,7 @@ assert(tonumber(string.rep('1', 32), 2) + 1 == 2^32) assert(tonumber('-fffffFFFFF', 16)-1 == -2^40) assert(tonumber('ffffFFFF', 16)+1 == 2^32) assert(tonumber('0xF') == 15) +assert(tonumber('5e-07') == 0.0000005) assert(1.1 == 1.+.1) print(100.0, 1E2, .01) diff --git a/baselib.go b/baselib.go index aa2c08a9..f655aea1 100644 --- a/baselib.go +++ b/baselib.go @@ -410,7 +410,7 @@ func baseToNumber(L *LState) int { L.Push(lv) case LString: str := strings.Trim(string(lv), " \n\t") - if strings.Index(str, ".") > -1 { + if strings.Contains(str, ".") || strings.Contains(str, "e-") { if v, err := strconv.ParseFloat(str, LNumberBit); err != nil { L.Push(LNil) } else {