View Issue Details

IDProjectCategoryView StatusLast Update
0008960Multi Theft Auto : San AndreasScriptingpublic2018-09-05 05:31
ReporterGallardo9944Assigned Toccw 
PrioritynormalSeverityminorReproducibilityrandom
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version1.5 
Summary0008960: Doing maths with getTickCount can return float values
Description

Sometimes doing stuff with getTickCount() returns float values (e.g. calculating time between two ticks). Seems to happen both clientside and serverside. It is absolutely random.

Steps To Reproduce

ER+#666666iGOR executed command: tick = getTickCount()
Command executed!

ER+#666666iGOR executed command: outputChatBox(getTickCount()-tick)
15216.999999998

ER+#666666iGOR executed command: outputChatBox(getTickCount()-tick)
65951.000000002

ER+#666666iGOR executed command: outputChatBox(getTickCount()-tick)
66346

ER+#666666iGOR executed command: outputChatBox(getTickCount()-tick.." ("..getTickCount().." || "..tick..")")
1686.0000000019 (10748630 || 10746944)

Additional Information

I'm not really sure if it's a problem with maths or getTickCount itself, but that's where I see this every day since official 1.5 release.

TagsNo tags attached.

Activities

arranTuna

2015-07-27 11:24

manager   ~~0023724

Last edited: 2015-07-27 11:26

View 2 revisions

This has existed for as long as I can remember, I've always just used math.floor() to hide it though.

As you've shown though it's not actually a bug with getTickCount() but when Lua does the maths on those large numbers so I don't think it's a bug for MTA to fix.

Jusonex

2015-07-27 12:20

administrator   ~~0023725

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Instead, you have to check if the floating point value is within a specified range. See https://en.wikipedia.org/wiki/Machine_epsilon for details.

ccw

2015-07-28 16:29

administrator   ~~0023734

Are you sure this happens on the client as well?

arranTuna

2015-07-31 20:46

manager   ~~0023770

Last edited: 2015-07-31 20:51

View 2 revisions

Tried:

crun setTimer(function() outputChatBox(getTickCount() - getTickCount() + 1 + 1.0) end, 100, 100)

Returned 2 every time.

Edit: Tried it on server and returns 2 every time as well, though.

AlexTMjugador

2015-08-03 17:06

viewer   ~~0023792

Last edited: 2015-08-03 17:06

View 2 revisions

It looks like the serverside rounding bug was likely fixed in this commit (r7393): https://github.com/multitheftauto/mtasa-blue/commit/dbb01f50e5b47bf35eb338fe205ae50dbb4c6438

Issue History

Date Modified Username Field Change