Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / What is the accuracy of floats?

Author
Message
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 5th Jun 2016 14:10
I am working on a statistics screen for my game where the player can track total time played as well as total deaths, XP and coins.

I was thinking of tracking the time as a float, but according to the timer() command, float accuracy will be lost after about 2 hours and AppGameKit doesn't have the double variable type. I expect most players will spend at least 5-10 hours on the game and some might spend far more. Should I be worried about inaccuracy and split this into 2 variables? Or perhaps only store the time as whole seconds in an integer?
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jun 2016 17:15
If your players are playing for 5 hours or more then I would think that they would be interested in time played to the nearest minute.

Time Played: 5 hours 23 minutes 47.342 seconds

looks a bit odd

If you need to retain accuracy, you can use resetTimer() to start back at zero, and have a second variable to store the additional time before the reset.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 5th Jun 2016 17:48
I will be presenting the time in the format HH:MM:SS. So I really only need accuracy down to 1 sec. My idea is to add the frame time to a timer variable. Right now I am thinking of "washing" it through a float and then add every full second to an integer. That means that the float won't loose any accuracy because I will keep reducing it by 1.0 every second.
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 5th Jun 2016 18:01
Reset each hour, count the hours in an integer, the timer is (minutes + seconds) as float. - accurate
If you want to be more precise, reset each minute. - very accurate
Or each second. - ultra accurate, but there isn't much use for that.

The worst case would be, that you have to use external bluetooth time measurement devices:
http://www.microsemi.com/products/timing-synchronization-systems/timing-synchronization-systems




[/url]
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 5th Jun 2016 21:33
Quote: "What is the accuracy of floats?"


AGK is single precision.

When I add the 3D physics to AppGameKit I tried to get Paul to go double precision so Bullet physics would be more accurate.
He claimed that ARM processors could not handle double precision.
The coffee is lovely dark and deep,and I have code to write before I sleep.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jun 2016 21:57
ARM processors are 4 to 8 times slower at double-precision floating point arithmetic. They also don't have any 64-bit vector instructions. So for gaming applications where speed is critical and accuracy beyond single-precision is secondary, I would agree that we need to wait for ARM to catch up.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 5th Jun 2016 22:16 Edited at: 5th Jun 2016 22:17
Quote: "Reset each hour, count the hours in an integer, the timer is (minutes + seconds) as float. - accurate
If you want to be more precise, reset each minute. - very accurate
Or each second. - ultra accurate, but there isn't much use for that."


The timer won't run when for example the menu is open. So I will be adding frame time to a float every frame the timer is running. So it's really easy to update an integer every second. And then I can do what I want with the integer without worrying about the float at all. So I have decided to go with that method.
Stab in the Dark software
Valued Member
21
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 6th Jun 2016 01:44
Quote: "ARM processors are 4 to 8 times slower at double-precision floating point arithmetic. They also don't have any 64-bit vector instructions. So for gaming applications where speed is critical and accuracy beyond single-precision is secondary, I would agree that we need to wait for ARM to catch up."


I disagree.
https://www.arm.com/products/processors/technologies/vector-floating-point.php
The coffee is lovely dark and deep,and I have code to write before I sleep.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jun 2016 08:34
In a couple of years, maybe the majority of phones will have the latest ARM chip and command sets. But right now, your average phone is running on an older version, or it is running later versions without the coprocessor to perform the faster calculations. Unfortunately, we don't control the devices that users have, and there are more mobile users that have no real knowledge of the tech in their phone than PC users.
Maybe it could be included as an additional data type in AppGameKit, then it is at the developer's discretion on whether they can afford the performance hit for their specific purpose.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 6th Jun 2016 13:57
Quote: "Maybe it could be included as an additional data type in AppGameKit, then it is at the developer's discretion on whether they can afford the performance hit for their specific purpose."


I think choice is always a good thing to have. Some might need it for specific things. Some might not be working on a mobile game. I have no need for doubles myself. If it takes long to add then it has to be weighted against other things that the community wants.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 6th Jun 2016 14:33
Single precision float has about 7 significant figures of accuracy (depending on the actual value). So by the time you reach one hour the timer value will be returning values in the thousands, lets say 3612.457 seconds, so it still has sub second accuracy, but as it gets to 10,000 and beyond you start to lose the milliseconds. If you only need the time to the nearest second you should be good up to a time value of about 16,000,000 seconds, or 185 days.
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 6th Jun 2016 14:50
I'd go with your first instinct DA and make your own counter - or have a counter per unit, like increment an integer with the elapsed time in milliseconds, decrementing by 1000 if it goes over 1000 and incrementing a seconds variable, which in turn increments minutes, and in turn hours. So 3 variables, seconds, minutes, hours... which is a bit of a hassle, but you'd be doing this anyway when formatting text - so I think your better off just keeping them separate and updating them with code based on the timer.

Also, it could probably be used as a trigger for updating the in-game time display - changing text strings in AppGameKit has so much to do, I prefer to only update text when absolutely necessary. I mean, to use the timer on its own to detect when to update a seconds time display can be fiddly, usually involves storing the previous timer value and comparing it. Storing minutes and hours separately may be overkill, it might make more sense to just calculate that from the seconds value, but I'm not a big fan of calculating that stuff.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 6th Jun 2016 16:30 Edited at: 6th Jun 2016 16:31
Paul:
Thanks, that's the reply I was looking for. It would have worked perfectly fine for me. But I have already implemented my own float to int idea Good to know how it works though.

Login to post a reply

Server time is: 2024-11-25 05:51:31
Your offset time is: 2024-11-25 05:51:31