What is a \"trap representation\" in C (some examples might help)? Does this apply to C++?
Given this code...
float f=3.5;
int *pi
In general, any non-trap IEEE-754 floating point value can be represented as an integer on some platforms without any issue. However, there are floating point values that can result in unexpected behavior if you assume that all floating point values have a unique integer representation and you happen to force the FPU to load that value.
(Example taken from http://www.dmh2000.com/cpp/dswap.shtml)
For instance, when working with FP data you need to marshal between CPUs with different endianness, you might think of doing the following:
double swap(double)
Unfortunately, if the compiler loads the input into an FPU register and it's a trap representation, the FPU can write it back out with an equivalent trap representation that happens to be a different bit representation.
In other words, there are some FP values that do not have a corresponding bit representation if you don't convert correctly (by correct I mean through a union
, memcpy
via char *
or other standard mechanism).