Always believed that double is 8 bytes. But recently I wondered, how can it be 8 bytes on a 32-bit computer? What turns out, one number is stored in two registers?

  • XMM / SSE / AVX registers are far from 32 bits ... - Vladimir Martyanov
  • @ Vladimir Martianov, and they just have floating point operations? - Alexander Elizarov
  • Including floating point operations. Maybe another calculation on ordinary instructions, a compiler can also make such a code - Vladimir Martyanov
  • From architecture strongly depends. the x86 initially had an FPU device (up to 80486DX was carried out in a separate x87 package). He has his own set of commands, and it was him who was considered the usual way of working with double. It includes 8 st0-st7 by 64 bit registers - Mike

1 answer 1

In accordance with the IEEE-754 standard, what you call a double is a double-precision number, ALWAYS 64 bits without questions (though the name may be different in different languages, not necessarily double). It is not required to be stored in registers, but may be stored in memory. Operations on these numbers are performed NOT in general-purpose registers (except for special tricks, and that is rare). There are also xmm registers in which 2 such numbers fit each and in which the compiler usually tries to push all actions. The processor's bit size does not play any role here, because there is no point in storing floating-point numbers in general-purpose registers (unless for some tricks with them). Floating arithmetic and integer are completely different spheres, and it will be a big mistake to confuse them. The previously obsolete long double type was generally 80 bits, now a number of well-known compilers do not support it at all. Numbers of this type were processed on FPU, whose stack could save up to 10 such numbers. The Standard still has quadruple precision numbers - 128 bits, but they are supported by hardware in few places, as well as half precision numbers - 16 bits (available on ARM in two versions - standard and extended).

The study of such numbers can begin with the simplest sources, such as Wikipedia .

  • Another useful resource in which there is, among others, a discussion of floating arithmetic . - Zealint