Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Best way to get an accurate result?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 86
Location: Another World - N5X2 106311411+2123518

PostPosted: Fri Jul 19, 2024 1:20 pm    Post subject: Best way to get an accurate result? Reply with quote

Hello All,
Whats the best way to get an accurate result for the 1st equation?
Code:
local a = 8608480567731124086
local b = 4304240283865562043 -- half of a

print(math.tointeger(a / 2))
-- result = 4304240283865562112 fail expected b
print(math.tointeger(b * 2))
-- result = 8608480567731124086 success = a
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 146

Joined: 06 Jul 2014
Posts: 4462

PostPosted: Fri Jul 19, 2024 1:53 pm    Post subject: This post has 1 review(s) Reply with quote

`a/2` converted the value to a double. Use `a//2` (integer division) instead
Code:
local a = 8608480567731124086
local b = 4304240283865562043

assert(a//2 == b)

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Flux.
Advanced Cheater
Reputation: 0

Joined: 10 Nov 2016
Posts: 86
Location: Another World - N5X2 106311411+2123518

PostPosted: Fri Jul 19, 2024 2:00 pm    Post subject: Reply with quote

Ok that works, thanks for that quick reply.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 34

Joined: 16 Feb 2017
Posts: 1402

PostPosted: Fri Jul 19, 2024 5:22 pm    Post subject: Reply with quote

What if there is no "b"? What if the results need to be extracted only from "a"?

Losses cannot be calculated because possible fractional division results are
passed through the "math.tointeger" or "math.floor" filter and rounded to an integer.

Here is a formula to calculate losses;

Code:
local a = 8608480567731124086

function divtointeger(...)
aa1 = tostring(...):gsub("%s","")
aa2,aa3,aa4 = string.match(aa1, "(%d+)(%p)(%d+)")
value = load('return '..aa1)()
a1 = math.tointeger(tonumber(value))
a3 = math.tointeger(tonumber(aa2) - a1)
a4 = math.tointeger(a3 - a1)
a5 = math.tointeger(a4 / 2)
a6 = math.tointeger(a1 + a5)
return a6
end

aa8 = divtointeger(a.." / 2")
print(aa8) -- 4304240283865562043

print(math.tointeger(aa8 * 2)) -- 8608480567731124086


-------------------------- Edit:
Ah this works @Parkour. Ok.

Code:
local a = 8608480567731124086

print(math.tointeger(a//2)) --> 4304240283865562043

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites