FROM : Shaun Wexler
DATE : Sun Nov 28 06:57:23 2004
On Nov 27, 2004, at 7:55 PM, M. Uli Kusterer wrote:
> At 17:28 Uhr -0800 26.11.2004, Shaun Wexler wrote:
>> Thanks! Might I suggest adding single-precision Float32, and display
>> exponent, mantissa, plus Nan, QNan, +/- Inf, and sign? That would be
>> very helpful too! ;)
>
> Well, a simple "float" field is in there now (1.0.3). I don't really
> have the info at hand about what part is the mantissa, etc.
#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);
For normalized floats, the value is -1^sign * 2e^exponent * (1.mantissa)
If denormalized, the value is -1^sign * 2e^-126 * (0.mantissa)
...where ^ means "to-the-power-of" and mantissa is the fractional part
with an implied significand, so for a normalized 3UL the exponent is 1
and the high bit of the mantissa is set: -1^0 * 2^1 * 1.5 == 3.0f.
--
Shaun Wexler
MacFOH
http://www.macfoh.com
DATE : Sun Nov 28 06:57:23 2004
On Nov 27, 2004, at 7:55 PM, M. Uli Kusterer wrote:
> At 17:28 Uhr -0800 26.11.2004, Shaun Wexler wrote:
>> Thanks! Might I suggest adding single-precision Float32, and display
>> exponent, mantissa, plus Nan, QNan, +/- Inf, and sign? That would be
>> very helpful too! ;)
>
> Well, a simple "float" field is in there now (1.0.3). I don't really
> have the info at hand about what part is the mantissa, etc.
#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);
For normalized floats, the value is -1^sign * 2e^exponent * (1.mantissa)
If denormalized, the value is -1^sign * 2e^-126 * (0.mantissa)
...where ^ means "to-the-power-of" and mantissa is the fractional part
with an implied significand, so for a normalized 3UL the exponent is 1
and the high bit of the mantissa is set: -1^0 * 2^1 * 1.5 == 3.0f.
--
Shaun Wexler
MacFOH
http://www.macfoh.com
| Related mails | Author | Date |
|---|---|---|
| M. Uli Kusterer | Nov 26, 16:15 | |
| Shaun Wexler | Nov 27, 02:28 | |
| Greg Hurrell | Nov 27, 17:31 | |
| M. Uli Kusterer | Nov 28, 04:55 | |
| Shaun Wexler | Nov 28, 06:57 | |
| Darrin Cardani | Nov 28, 17:00 |






Cocoa mail archive

