In the stdint.h (C99), boost/cstdint.hpp, and cstdint (C++0x) headers there is, among others, the type int32_t.
Are there similar fixed-size floating point types? Something like float32_t?
In the stdint.h (C99), boost/cstdint.hpp, and cstdint (C++0x) headers there is, among others, the type int32_t.
Are there similar fixed-size floating point types? Something like float32_t?
Nothing like this exists in the C or C++ standards at present. In fact, there isn't even a guarantee that float
will be a binary floating-point format at all.
Some compilers guarantee that the float
type will be the IEEE-754 32 bit binary format. Some do not. In reality, float
is in fact the IEEE-754 single
type on most non-embedded platforms, though the usual caveats about some compilers evaluating expressions in a wider format apply.
There is a working group discussing adding C language bindings for the 2008 revision of IEEE-754, which could consider recommending that such a typedef be added. If this were added to C, I expect the C++ standard would follow suit... eventually.
If you want to know whether your float
is the IEEE 32-bit type, check std::numeric_traits<float>::is_iec559
. It's a compile-time constant, not a function. If true
, then assume away. If false
, you might be able to find a platform flag that guarantees IEEE formatting: it might only be false because of operating restrictions.
EDIT: I just poked at my computer (OS X x64) for a bit and discovered that is_iec559
is true
for long double
despite a dodgy memory layout: the number is rotated by 16 bits, then put in little-endian 64-bit halves arranged in big-endian order. The C++ standard, even C++0x, doesn't define what IEEE compliance means or even which revision of IEEE 754 it's referring to. So, be careful :v( .
EDIT 2: is_iec559
is true for long double
on Mac OS X at least despite being the non-IEEE 80-bit Intel format. So indeed, that sucks.
EDIT 3: Apparently the confusion is exacerbated by C99 §F.2/1 footnote 307,
307) ‘‘Extended’’ is IEC 60559’s double-extended data format. Extended refers to both the common 80-bit and quadruple 128-bit IEC 60559 formats.
Which is a direct self contradiction. If ‘‘Extended’’ is IEC 60559’s double-extended data format.
then refers to both
is obviously impossible. It's fairly obvious that one format is proper IEEE and the other is an anachronism, but I'm guessing that Intel corrupted the standard to grandfather in their hardware. Yecchh. There's your language standard encouraging hardware improvement!
On the other hand, C99 defines 754 compliance as a binary issue: either the entire implementation complies or it doesn't. Either Intel 80 is 754 or the machine can't ever use Intel 80 or the system is non-compliant. C++ provides an answer to the specific question of whether the 80-bit format comes from 754, and carrying over C99's generalizing seems inappropriate.