Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Determine a value is INTEGER
#2
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)?

(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.
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why are SINGLE variables faster than INTEGER variables ? Elzaimer 18 2,342 07-07-2025, 05:01 AM
Last Post: ahenry3068
  generating a random number in the full range of that number? (Integer, Long) madscijr 2 651 05-01-2025, 09:11 PM
Last Post: madscijr
  testing a number's quare root is an integer and casting to a value? madscijr 22 3,422 01-29-2025, 11:12 PM
Last Post: Pete
  When MUST a variable be an Integer? Dimster 3 877 04-27-2024, 07:04 PM
Last Post: TerryRitchie
  Looking for a solution to determine the thread count via API SagaraS 4 1,060 04-08-2024, 04:19 AM
Last Post: SpriggsySpriggs

Forum Jump:


Users browsing this thread: 1 Guest(s)