Author: Jon SargeantJon Sargeant
Date: Apr 19, 2008 22:14
Hi,
I'm looking for a general purpose way of initializing a floating-point
constant with an arbitrary bit pattern using C99. For example,
const unsigned int x=0x3f800000U; //assume 32-bits
const float y=*(float*)&x; //assume 32-bit single-precision IEEE754
Compiling this code on GCC generates the error "initializer element is
not constant". C99 hex floats are a partial solution. I can enter
plus/minus zero, finites, infinites (using 1.0/0.0 and -1.0/0.0), but
NaNs have me stumped. How do I get a constant NaN with a specific
payload? nan() looked promising until I realized that it returns a
variable. Any ideas?
Thanks,
Jon
|