Skip navigation.
 
mlRe: [ANN] Value Converter
FROM : Darrin Cardani
DATE : Sun Nov 28 17:00:13 2004

At 6:16 AM -0800 11/28/04, Shaun Wexler <<email_removed>> wrote:
>#include <std_disclaimer.h> // written in Mail.app
>
>extern float *theFloat;
>
>int float32i = *(int *)theFloat;
>int exponent = ((float32i & 0x7f800000) >> 23) - 127;
>int mantissa = float32i & 0x007fffff;
>int sign = float32i >> 31;
>BOOL isNegative = (sign == 1);
>BOOL isDenormal = (exponent == 0 && mantissa != 0);
>BOOL isInfinity = (exponent == 128 && mantissa == 0));
>BOOL isNan = (exponent == 128 && mantissa != 0);
>BOOL isQNan = isNan && (mantissa & 0x00400000 != 0);


You can also use fpclassify () from the standard <cmath> header. It
will return the standard constants FP_NORMAL, FP_NAN, FP_INFINITE,
FP_ZERO, and FP_SUBNORMAL. (I don't see anything about QNan, though.)
Writing it that way may make it easier to keep working on later or
alternate OSes. It also has a macro for getting the sign bit, called
signbit ().

Darrin
--
Darrin Cardani - <email_removed>
President, Buena Software, Inc.
<http://www.buena.com/>
Video, Image and Audio Processing Development

Related mailsAuthorDate
ml[ANN] Value Converter M. Uli Kusterer Nov 26, 16:15
mlRe: [ANN] Value Converter Shaun Wexler Nov 27, 02:28
mlRe: [ANN] Value Converter Greg Hurrell Nov 27, 17:31
mlRe: [ANN] Value Converter M. Uli Kusterer Nov 28, 04:55
mlRe: [ANN] Value Converter Shaun Wexler Nov 28, 06:57
mlRe: [ANN] Value Converter Darrin Cardani Nov 28, 17:00