Lee Rhodes schrieb:
[...]
0 01111111111 1000000000000000000000000000000000000000000000000000
The union is the only way I know to get this using c/c++:
union Dbits {
double d;
ULL bits;
}
It is very efficient requiring no method calls or other overhead. (Note
that Java at least recognized this need with its
Double.doubleToRawLongBits() and related methods.)
So how "implementation-dependent and dangerous" is this conversion?
1) IEEE-754: Today the IEEE-754 standard (especially the 32 and 64 bit
formats) is the most widely-used standard for floating point computation by
far. For the increasingly rare machines that don't support this
standard...well, fortunately, I don't need to worry about writing reusable
code for them.
2) unsigned long long (ULL): now this may be dangerous. I have not figured
out a way to define an integral type that is EXACTLY 64 bits
At least this one is, in C++, not that difficult (as long as we can assume
8-bit characters. Anachronistic architectures that use(d) 10-bit
characters or so are probably also on your "don't care list" :-) )
See http://gcc.gnu.org/ml/gcc-help/2007-06/msg00259.html
Daniel