View Issue Details

IDProjectCategoryView StatusLast Update
0008853Multi Theft Auto : San AndreasScriptingpublic2015-07-26 01:48
ReporterGallardo9944Assigned Toccw 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version1.4 
Target Version1.5Fixed in Version1.5 
Summary0008853: toJSON passes wrong floats
Description

toJSON converts "normal" floats to long and wrong ones

Steps To Reproduce

/run outputChatBox(toJSON({5.1}))
[ [ 5.0999999046325684 ] ]

Additional Information

Detected after reporting http://bugs.mtasa.com/view.php?id=8848

TagsNo tags attached.

Activities

sbx320

2015-05-16 23:09

administrator   ~~0023280

That's how IEEE floating point numbers work. The best representation for 5.1 is 5.099999904632568.

ccw

2015-05-27 09:51

administrator   ~~0023320

Would be nice to do something about this.
I noticed we are float casting when going to/from json, so keeping the double would help.
I also found this: https://github.com/json-c/json-c/pull/59
It seems the json developers have been fiddling with the double to string conversion. They say that %.17g is best because numbers like 12.300000000000001 won't get rounded to 12.3
If we disagree and think 12.3 is better, then we'll have to change the json source to use %.16g or less.

Gallardo9944

2015-07-25 22:49

viewer   ~~0023719

Seems like it's fixed in 1.5.

ER+#666666iGOR executed command: outputChatBox(toJSON({5.1}))
[ [ 5.1 ] ]

ER+#666666iGOR executed command: outputChatBox(toJSON(123.321))
[ 123.321 ]

Issue History

Date Modified Username Field Change