David Harmon wrote:
On 23 Jan 2004 01:48:22 -0800 in comp.lang.c++,
jo**********************@yahoo.es (jose luis fernandez diaz) was alleged
to have written:
How can I print the binary base of a long double ?
The very thought of doing such a low-level and implementation
specific thing is naughty. Nevertheless...
Create a union type containing a long double and
array of char[sizeof(long double}]. Assign to the long
double member, then print the chars one by one. This yields
explicitly "undefined behavior", but has been known to work
for some implementation.
Why use undefined behavior and risk complete failure when there's a
simple way to do it in a well-defined manner?
long double val = 12.34;
unsigned char bytes[sizeof(long double)];
memcpy(bytes, &val, sizeof(val));
Now 'bytes' contains the object-representation (C99 term for it) of val,
and you can print it out however you see fit.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.