home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------
- * filename - frexp.cas
- *
- * function(s)
- * frexp - splits a double number into mantissa and exponent
- *-----------------------------------------------------------------------*/
-
- /*[]------------------------------------------------------------[]*/
- /*| |*/
- /*| Turbo C Run Time Library - Version 3.0 |*/
- /*| |*/
- /*| |*/
- /*| Copyright (c) 1987, 1990 by Borland International |*/
- /*| All Rights Reserved. |*/
- /*| |*/
- /*[]------------------------------------------------------------[]*/
-
-
- #pragma inline
- #include <asmrules.h>
-
- #include <_math.h>
- #include <math.h>
-
- static int minus1 = -1;
-
- /*--------------------------------------------------------------------------*
-
- Name frexp - splits a double number into mantissa and exponent
-
- Usage double frexp(double value, int *expP);
-
- Prototype in math.h
-
- Description Split a floating point number into its exponent and
- fractional parts, with the exponent placed into *expP, and
- the fraction is the function return value.
-
- Return value frexp returns value - (*expP = chop (value));
-
- *---------------------------------------------------------------------------*/
- #pragma warn -rvl
- double frexp (double value, int *expP)
- {
- unsigned statword;
- asm FILD W0 (minus1)
- asm FLD DOUBLE (value)
- asm FXTRACT /* ST(1) = exponent, (pushed) ST = fraction */
- asm FXCH
-
- /*
- The FXTRACT instruction normalizes the fraction 1 bit higher than
- wanted for the definition of frexp() so we need to tweak the result
- by scaling the fraction down and incrementing the exponent.
- */
-
- asm LES_ bx, expP
- asm FISTP W0 (ES_ [bx])
- asm FSCALE /* fraction scaled as C expects */
-
- /* if number was 0, don't touch exponent */
- asm FXAM
- asm FSTSW statword
- asm FWAIT
- asm mov ah, BY1(statword)
- asm sahf
- asm jz done
- asm inc W0 (ES_ [bx]) /* exponent biased to match */
-
- done:
- asm FSTP ST(1) /* discard minus1, leave fraction as TOS */
- frx_end:
- return;
- }
- #pragma warn .rvl
-