home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------
- * filename - modf.cas
- *
- * function(s)
- * modf - splits 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>
-
-
- /*--------------------------------------------------------------------------*
-
- Name modf - splits into mantissa and exponent
-
- Usage double modf(double value, double *wholeP);
-
- Prototype in math.h
-
- Description modf breaks the double value into two parts: the integer
- and the fraction. It stores the integer in wholeP and
- returns the fraction.
-
- Return value modf returns the fractional part of value.
-
- *---------------------------------------------------------------------------*/
- #pragma warn -rvl
- double modf (double value, double *wholeP)
- {
- asm FLD DOUBLE (value)
-
- asm mov ax, value [6]
- asm shl ax, 1
- asm cmp ax, 0FFE0h /* infinite exponent ? */
- asm jnb mdf_infinite
-
- asm FLD st(0) /* duplicate ST */
-
- asm push ax /* make a word on the stack */
- asm mov bx, sp
-
- asm FSTCW W0 (SS_ [bx]) /* read out the current control word */
- asm mov ax, 0F3FFh
- asm FWAIT
- asm and ax, SS_ [bx] /* mask out the rounding control */
- asm or ah, 0Ch /* chop towards zero */
- asm push ax
- asm FLDCW W0 (SS_ [bx-2])
- asm pop ax
-
- asm FRNDINT /* round to integer */
-
- asm FLDCW W0 (SS_ [bx]) /* restore original rounding control */
- asm pop ax
-
- asm LES_ bx, wholeP
- asm FST DOUBLE (ES_ [bx]) /* *wholeP = chop (value) */
-
- asm FSUBP st(1), st /* fraction = value - chop(value) */
-
- mdf_end:
- return;
-
- mdf_infinite: /* infinity == rounded (infinity) */
- asm LES_ bx, wholeP
- asm FSTP DOUBLE (ES_ [bx])
- asm FLDZ /* zero = infinity - infinity */
- asm jmp short mdf_end
- }
- #pragma warn .rvl
-