Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determine a value is INTEGER
#5
(07-26-2024, 02:02 AM)TerryRitchie Wrote: 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.

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.
In that case I would check for an integer within a tolerance (Ex. within `.00001` or something similar), that should be fine since an extra `.00001`in either direction is unlikely to change the answer enough to matter. The tolerance range itself doesn't need to be all that exact, the error should generally be smaller than that number I gave and in the worst case you'll just fall back to the floating-point version and thus still get the right answer.

I suppose alternatively you could multiple the number by 10 or 100 and increase the size of your table for higher accuracy, but that might make it prohibitively large.

For something like screen coordinates this issue doesn't really matter because you're going to round to the nearest integer in the end and use whatever you get. The sin/cos situation is special because you want to do something different if the number isn't an integer vs. just chop off the fractional part.
Reply


Messages In This Thread
Determine a value is INTEGER - by TerryRitchie - 07-25-2024, 07:40 PM
RE: Determine a value is INTEGER - by DSMan195276 - 07-26-2024, 12:17 AM
RE: Determine a value is INTEGER - by Pete - 07-26-2024, 12:23 AM
RE: Determine a value is INTEGER - by DSMan195276 - 07-26-2024, 02:33 AM
RE: Determine a value is INTEGER - by Pete - 07-26-2024, 02:41 AM
RE: Determine a value is INTEGER - by Jack - 07-26-2024, 12:25 PM
RE: Determine a value is INTEGER - by Petr - 07-26-2024, 03:02 PM
RE: Determine a value is INTEGER - by Jack - 07-26-2024, 05:25 PM
RE: Determine a value is INTEGER - by DSMan195276 - 07-26-2024, 07:02 PM
RE: Determine a value is INTEGER - by Jack - 07-26-2024, 08:14 PM
RE: Determine a value is INTEGER - by Kernelpanic - 07-26-2024, 10:57 PM
RE: Determine a value is INTEGER - by DSMan195276 - 07-27-2024, 04:30 AM
RE: Determine a value is INTEGER - by Kernelpanic - 07-27-2024, 05:03 PM
RE: Determine a value is INTEGER - by SMcNeill - 07-27-2024, 01:49 PM
RE: Determine a value is INTEGER - by bplus - 07-27-2024, 02:43 PM



Users browsing this thread: 7 Guest(s)