Skip to main content
gamedev.net
🔒 Locked

Integer and Floating point precision

Started by Lode Jul 11, 2004 at 4:16 AM 5 replies 550+ views
Original Post
Lode
Lode
On a 32-bit processor, an integer is 32 bit, a floating point number 32 bit, a double 64 bit and a "long double" 80 bit. Which of those are defined by the processor, and which by C++? Why is a double 64-bit, on a 32-bit processor? How can a 32-bit processor work with that? On the new 64 bit processors, has the precision of the calculations increased? Are integers there 64 bit by default? And are 128 bit floating point numbers supported there, or even 160 bit ones? Do there exist processors that can natively calculate with much higher precision floating point numbers?
etothex
etothex
Compiling with gcc, you can use the -m128bit-long-double option for 128 bit long doubles. And long doubles are 96 bits, aren't they? Or am I wrong?

And for the integers, 'int' is the same as the word on the cpu(32bits for i386, 16bits for 286, 64 bits x86-64) while the others(long, short, etc) are guaranteed to be 32, 16, etc. IIRC :)

*edit Yep, on gcc long double = 96 bits
smart_idiot
smart_idiot
I think the FPU does it's calculating in 80 or 92 or something bits, and it gets reduced to 32 or 64 when the number gets stored in ram.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
etothex
etothex
Quote:
Original post by smart_idiot
I think the FPU does it's calculating in 80 or 92 or something bits, and it gets reduced to 32 or 64 when the number gets stored in ram.


Yes, on all cpus pentium something or above, calculations are rounded, so it's almost worthless to go for less precision, unless you're using sse and batching them or something.
Lode
Lode
Quote:
Original post by smart_idiot
I think the FPU does it's calculating in 80 or 92 or something bits, and it gets reduced to 32 or 64 when the number gets stored in ram.


Do the FPU's of 64 bit processors use more precision than this 80 or 92?
doynax
doynax
Quote:
Original post by Lode
Do the FPU's of 64 bit processors use more precision than this 80 or 92?

All x86 fpus (including the 8087) use 80 bit precision internally by default. Some 64-bit architectures (eg. mips) can also work with 128 bit floats.

C itself doesn't specify anything other than minimum limits and relations between the types' sizes, so compilers can choose a cpu's native (fastest) types.
Fruny
Fruny
Quote:
Original post by Lode
On a 32-bit processor, an integer is 32 bit, a floating point number 32 bit, a double 64 bit and a "long double" 80 bit.
Which of those are defined by the processor, and which by C++?


None of these are defined by C++, which only states that a double has at least as much precision as a float and a long double at least as much precision as a double. It is not uncommon for the extended-precision (long double) type to be identical to the double-precision (double) type.

Similarly, for integer types, all you get is an ordering, where char <= short <= int <= long. The only type with a known size is char, which has a size of 1. Incidentally, C++ defines 'byte' in terms of 'char' and not the other way around.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.