Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #472: tonumber does not handle E notation correctly #473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _lua5.1-tests/math.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ assert(tonumber'+ 0.01' == nil and tonumber'+.e1' == nil and
tonumber'.' == nil)
assert(tonumber('-12') == -10-2)
assert(tonumber('-1.2e2') == - - -120)
assert(tonumber('2e2') == 200)
assert(tonumber('2e2', 15) == 662)
assert(f(tonumber('1 a')) == nil)
assert(f(tonumber('e1')) == nil)
assert(f(tonumber('e 1')) == nil)
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 base == 10 && strings.ContainsAny(str, ".eE") {
if v, err := strconv.ParseFloat(str, LNumberBit); err != nil {
L.Push(LNil)
} else {
Expand Down