Recent

Author Topic: float, real, double - which one  (Read 417 times)

Weiss

  • Full Member
  • ***
  • Posts: 213
float, real, double - which one
« on: May 12, 2025, 10:24:21 am »
probably stupid question, but I have no idea which one is "better"? To me they all mean real number type. Documentation only muddied the issue further. When I create an application for Windows, which one should I be picking and is there any drawback to any of those types?

So far I have been mixing them up without thinking. Did not notice the difference, but maybe there is one.

Khrys

  • Full Member
  • ***
  • Posts: 241
Re: float, real, double - which one
« Reply #1 on: May 12, 2025, 11:55:52 am »
Float  - platform-dependent most precise float type available, e.g. an alias of  Extended  on x86, which takes up 10 bytes (80 bits); supported only via the old x87 instructions (not vectorizable, inefficient) - use only if you have concrete (measurable) evidence that  Double  doesn't have enough precision for your use case

Double  - takes up 8 bytes (64 bits); very good precision that IMO far outweighs its larger memory footprint compared to  Single; most scalar instructions (multiply, add) are as fast as the corresponding  Single  versions

Single  - takes up 4 bytes (32 bits); good for very large amounts of data where precision isn't the main concern (such as 3D model data)

Real - platform-dependent alias of either  Double  (if an FPU is available) or  Single  (if floating-point support must be emulated in software); de facto equivalent to  Double  on x86 and ARM (A-profile)



Personally I'd stick to  Double  almost everywhere.

ASerge

  • Hero Member
  • *****
  • Posts: 2418
Re: float, real, double - which one
« Reply #2 on: May 13, 2025, 02:16:25 am »
Float  - platform-dependent most precise float type available, e.g. an alias of  Extended  on x86, which takes up 10 bytes (80 bits); supported only via the old x87 instructions (not vectorizable, inefficient) - use only if you have concrete (measurable) evidence that  Double  doesn't have enough precision for your use case
Type Float from the Math unit. Type ValReal (of the same purpose) from the System unit.

 

TinyPortal © 2005-2018