Float to sign/exp/mantissa

Andrew Koenig ark at alice.UUCP
Wed Apr 5 03:09:13 AEST 1989


In article <1026 at cs-spool.calgary.UUCP>, paquette at cpsc.ucalgary.ca (Trevor Paquette) writes:

>    I am sure that someone out there has a routine that given
> a floating point number, what is the sign, exponent and mantissa
> of the number..

The widely available frexp() library function gives you most
of what you want.  After executing the following:

	double x;
	double frexp();
	double mant;
	int exp;

	x = /* some value */;

	mant = frexp(x, &exp);

you are guaranteed that x is equal to mant * 2^^exp (here, ^^ means
exponentiation), that 0.5 <= |mant| < 1, and that the sign of mant
is the same as the sign of x, except that if x is 0, mant and exp
will be 0 too.

That should make it easy for you to get what you want.
-- 
				--Andrew Koenig
				  ark at europa.att.com



More information about the Comp.sys.sgi mailing list