Re: [Boost-users] [serialization]
On Sun, 2005-11-13 at 16:02 -0800, Robert Ramey wrote:
Truth is, I don't even know how one goes about assigning a NaN or a +/inf to floating/double variable !!
Not an expert here like you guys, but how about: #include <limits> double x_NaN = std::numeric_limits<double>::quiet_NaN(); double y_PlusInfinity = std::numeric_limits<double>::infinity(); double z_MinusInfinity = -std::numeric_limits<double>::infinity(); ... Also, here is some concise info on IEEE standard floating point numbers available from the Internet: The following notes are reproduced from http://stevehollasch.com/cgindex/coding/ieeefloat.html Infinity The values +infinity and -infinity are denoted with an exponent of all 1s and a fraction of all 0s. The sign bit distinguishes between negative infinity and positive infinity. Being able to denote infinity as a specific value is useful because it allows operations to continue past overflow situations. Operations with infinite values are well defined in IEEE floating point. Not A Number The value NaN (Not a Number) is used to represent a value that does not represent a real number. NaN's are represented by a bit pattern with an exponent of all 1s and a non-zero fraction. There are two categories of NaN: QNaN (Quiet NaN) and SNaN (Signalling NaN). A QNaN is a NaN with the most significant fraction bit set. QNaN's propagate freely through most arithmetic operations. These values pop out of an operation when the result is not mathematically defined. An SNaN is a NaN with the most significant fraction bit clear. It is used to signal an exception when used in operations. SNaN's can be handy to assign to uninitialized variables to trap premature usage. Semantically, QNaN's denote indeterminate operations, while SNaN's denote invalid operations. The definition of NaNs, signed zero and infinity, and denormalized numbers from "IEEE Standard for Binary Floating-Point Arithmetic", ANSI/IEEE Standard 754-1985, Institute of Electrical and Electronics Engineers, August 1985., is reproduced below. In the following, 'S' stands for the sign bit, 'E' for the exponent, and 'F' for the fractional part. The symbol 'u' stands for an undefined bit (0 or 1). Type S (1 bit) E (11 bits) F (52 bits) signaling NaN u 2047 (max) .0uuuuu---u (with at least one 1 bit) quiet NaN u 2047 (max) .1uuuuu---u negative infinity 1 2047 (max) .000000---0 positive infinity 0 2047 (max) .000000---0 negative zero 1 0 .000000---0 positive zero 0 0 .000000---0 Kevin Carroll
participants (1)
-
Kevin Carroll