2017-07-25 00:47 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000328Cheat Enginepublic2015-04-30 04:53
Reporterflarn2006 
Assigned ToDark Byte 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Summary0000328: Lua tonumber() function not returning negative numbers in some cases
DescriptionFor some reason, when using the tonumber() function on a string containing a negative number, starting with "-0.", it returns the absolute value of that number. This happens with any negative number -1 < x < 0, and only when the zero is given before the decimal point in the string.

To reproduce:

Open Lua Engine window, and type: print(tonumber("-0.028"))

Then click Execute. It will say "0.028", while it should say "-0.028".
TagsNo tags attached.
Attached Files

-Relationships
+Relationships

-Notes

~0000675

Dark Byte (developer)

Last edited: 2014-05-03 14:06

Confirmed. The problem is that this is lua which is an external library. There is a new version, but it's missing some of the patches I need (large number support)

But for now you can 'fix' the problem by always executing this script (it could be improved to deal with annoying users that do ----0.12 or add spaces in front, but you should get the idea)

---
if original_tonumber==nil then
  original_tonumber=tonumber
end

function tonumber(value)
  local result=original_tonumber(value)
  if string.sub(s,1,1)=="-" then
    if result>0 then
      result=-result
    end
  end

  return result
end
--

place it in main.lua, or in the autorun folder, or just in the start of your tables/trainers if they use it

~0000676

mgr_inz_Player (reporter)

function tonumber2(value)
  value = value:gsub( "%-0*%." , "-." ):gsub("%-%-","")
  return tonumber(value)
end

test1 = "-0.234"
test2 = "-000.234"
test3 = "---0.234"
test4 = "-----0000.234"
test5 = "------0000.234" -- positive value. ( -1^6 )

print( tonumber2(test1) )
print( tonumber2(test2) )
print( tonumber2(test3) )
print( tonumber2(test4) )
print( tonumber2(test5) )



output:
-0.234
-0.234
-0.234
-0.234
0.234

~0000677

flarn2006 (reporter)

@Dark Byte: That's pretty much what I did, but thanks! :-)

~0000816

Dark Byte (developer)

fixed now that ce is using Lua 5.3
+Notes

-Issue History
Date Modified Username Field Change
2014-05-01 01:54 flarn2006 New Issue
2014-05-03 14:04 Dark Byte Note Added: 0000675
2014-05-03 14:04 Dark Byte Status new => confirmed
2014-05-03 14:06 Dark Byte Note Edited: 0000675
2014-05-05 15:03 mgr_inz_Player Note Added: 0000676
2014-05-05 15:04 flarn2006 Note Added: 0000677
2015-04-30 04:53 Dark Byte Note Added: 0000816
2015-04-30 04:53 Dark Byte Status confirmed => resolved
2015-04-30 04:53 Dark Byte Resolution open => fixed
2015-04-30 04:53 Dark Byte Assigned To => Dark Byte
2016-06-05 15:18 Jptnuc Issue cloned: 0000487
+Issue History