0

Does it make any difference in having a 32 or 64-bit CPU in the amount of precision that IEEE 754 provides?

I mean when programming in C whether the size of float, double and long double are different between a 32 or 64-bit CPU.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Janus Gowda
  • 295
  • 1
  • 4
  • 17

4 Answers4

4

In most architectures that use IEEE-754, float and double are exact 32 and 64-bit types corresponding to single and double precision respectively. Therefore the precision is the same whether you're on a 32 or a 64-bit computer. The exceptions are some microcontrollers with non-standard-compliant C compilers where both double and float are the same and contain 32 bits

OTOH long double support varies depending on system. On x86 most implementations will utilize the hardware 80-bit extended precision type (often padded to 12 or 16 bytes in order to maintain alignment), except MSVC where long double is just an alias for double. On other architectures long double are often implemented as either

  1. The same type as double, or
  2. 128-bit IEEE 754-2008 quadruple precision, or
  3. 128-bit double-double

While the second way increases both range and precision significantly compared to double, it's also often significantly slower due to the lack of hardware support

The double-double method results in a type with in the same range but twice the precision of double, with the advantage of hardware double support, i.e. you don't need to implement entirely in software like quadruple precision. However it's not IEEE-754 compliant

If you're doing a lot of math on or , moving to 64-bit would benefit because of the increased number of registers, SSE2/Neon available by default... which improves performance compared to the 32-bit version, unlike most other architectures where 64-bit programs often run slower due to bigger pointers.

phuclv
  • 37,963
  • 15
  • 156
  • 475
2

It is common to most 32-bit and 64-bit machines for float to be IEEE-754 32-bit floating point, and double to be IEEE-754 64-bit floating point. Some implementations might use the IEEE-754 80-bit type as double (or long double).

Lee Daniel Crocker
  • 12,927
  • 3
  • 29
  • 55
1

No, there is no difference, you can confirm this by checking sizeof(float) across both architectures. If you need greater precision use double.

Geoffrey
  • 10,843
  • 3
  • 33
  • 46
  • So does not offer any advantage to C programmers of mathematics applications a 64bit CPU? – Janus Gowda Jul 24 '13 at 16:28
  • 1
    Do not quote me on this, but `double` performance on 64bit should be faster then 32bit depending on what you are doing since a double value is 64 bits long. It also depends on the FPU. – Geoffrey Jul 24 '13 at 16:31
  • 1
    64-bit means a wider (faster) bus. So there would be some speed up there. 64-bit FPU would also process doubles better. – Jiminion Jul 24 '13 at 16:31
1

Assuming float and double map to IEEE-754 single-precision and double-precision numbers respectively, then no, there is no difference.

long double may be a different story, however, since compilers may choose to pad it to an even size.

Drew McGowen
  • 11,471
  • 1
  • 31
  • 57