07-26-2024, 02:02 AM
(This post was last modified: 07-26-2024, 02:06 AM by TerryRitchie.)
(07-26-2024, 12:17 AM)DSMan195276 Wrote: I would look at it a different way - if the value is supposed to be an integer, why aren't you using an integer variable from the start? And if it won't always be an integer, why do you care if it's specifically an integer (vs. just close to an integer)?The reason I was looking into this was the need to test if a SINGLE value is an INTEGER. I developed a roto-zoom function that uses a COS/SIN lookup table if integers are passed and uses traditional trig if non-integers are passed. The function performs many times faster if only integers are used but I've noticed hiccups here and there in the speed which led to me to those discussions on other web sites. General rotation of a ship in games is easily done with integer degrees. But having an enemy ship point directly at the player ship from a distance all the way across the screen would require more precision than integers could provide, for instance. Hence, the reason I developed the hybrid roto-zoom routine.
(07-25-2024, 07:40 PM)TerryRitchie Wrote: Could any "floating point anomalies" with QB64 affect the method I have shown above?Yes, the issues are common to all languages that use the IEEE-754 representation of floating-point values (which is most of them).
The key issue is that even if your floating-point values start out as integers, they might not still be integers when you go to check them. Ex. Operations that should round-trip back to an integer may not do so due to floating-point error, such as several division and multiplication steps. In general it's very hard to guarantee this won't happen, and much easier to simply allow for it to happen and check for values within a certain tolerance of the expected value.
Another use case for using SINGLE values where INTEGERs are used is screen coordinates. When calculating the positions, vectors, and magnitudes of objects you must use SINGLE values for accuracy but then use the INTEGER portion for screen placement.
From what Pete has shown perhaps a very small threshold check should somehow be implemented? I kept seeing code on the other sites implementing 1e-5 which I believe is part of their threshold check. That didn't make much sense to me until Pete's explanation.
Yeah Pete, there were also those on the other sites showing what did, convert to a string first. Which again, I thought was rather odd until your explanation.