Skip to content

Commit

Permalink
Issue yuin#491 : Add a condition to check to parseFloat or parseInt
Browse files Browse the repository at this point in the history
  • Loading branch information
longquan0104 committed Jun 2, 2024
1 parent 2348fd0 commit b44e760
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions _lua5.1-tests/math.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion baselib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Binary file added glua
Binary file not shown.

0 comments on commit b44e760

Please sign in to comment.