Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why are SINGLE variables faster than INTEGER variables ?
#14
(06-27-2025, 05:44 PM)madscijr Wrote:
(06-27-2025, 01:45 PM)SMcNeill Wrote: Integer Division (the \ division) is much faster than taking the integer value of normal division, as shown above.

x \ y is faster than INT(x / y).   At least, it always has been for me on Windows with the math processors on my PCs and Laptops.  Perhaps Linux or Mac handles them differently somehow?

No kidding? 

This is very very useful to know for any QB64 / QB64PE programmer, thanks for sharing.

Do we by chance have a FAQ anywhere with these little bits of wisdom collected together?

(06-27-2025, 04:21 PM)Kernelpanic Wrote: Yes, floating-point division can be faster than integer division under certain circumstances, especially if the processor has an efficient floating-point unit (FPU) and the hardware support for floating-point operations is optimized. However, this depends heavily on the specific hardware, the compiler used, and the exact data.
. . .
In summary:
While integer division can be faster in some cases, especially when high precision is not required or when the result needs to be rounded to an integer, floating-point division is often faster when the processor has a well-optimized FPU and the compiler adjusts the code accordingly. The actual speed depends on many factors and can therefore vary.

Hmm... I wonder if there is a way to check the hardware from code, so your program can choose the faster method at runtime, depending on the FPU type detected?

     Also when using Integer's the NATIVE REGISTER SIZE is going to be fastest.   On modern systems that _INTEGER64 !! Not Integer or Even Long. !!!

   Honestly.   Unless your doing something really, really performance critical then IMHO it really doesn't matter a lot I usually use DOUBLE as It doesn't very often overflow. !!.        The only time I use _byte, integer or long is when I'm doing file parsing then the file format selects the required data type !!!
Reply


Messages In This Thread
RE: Why are SINGLE variables faster than INTEGER variables ? - by ahenry3068 - 06-28-2025, 12:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  _NEWIMAGE can't accept variables as dimensions? bobalooie 23 910 02-18-2026, 11:16 PM
Last Post: Unseen Machine
  generating a random number in the full range of that number? (Integer, Long) madscijr 2 641 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,374 01-29-2025, 11:12 PM
Last Post: Pete
  Determine a value is INTEGER TerryRitchie 17 3,260 07-27-2024, 05:03 PM
Last Post: Kernelpanic
  Is there a faster way to do this glow circle effect? Dav 11 2,067 06-16-2024, 11:51 PM
Last Post: Dav

Forum Jump:


Users browsing this thread: 1 Guest(s)