Re: [ANN] Value Converter
Re: [ANN] Value Converter
- Subject: Re: [ANN] Value Converter
- From: Shaun Wexler <email@hidden>
- Date: Sat, 27 Nov 2004 21:57:23 -0800
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden