home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / MATH.ZIP / MODF.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.4 KB  |  85 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - modf.cas
  3.  *
  4.  * function(s)
  5.  *        modf - splits into mantissa and exponent
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987, 1990 by Borland International        |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21.  
  22. #include <_math.h>
  23. #include <math.h>
  24.  
  25.  
  26. /*--------------------------------------------------------------------------*
  27.  
  28. Name        modf - splits into mantissa and exponent
  29.  
  30. Usage        double    modf(double value, double *wholeP);
  31.  
  32. Prototype in    math.h
  33.  
  34. Description    modf breaks  the double value  into two parts:    the integer
  35.         and  the fraction.  It stores    the integer  in wholeP    and
  36.         returns the fraction.
  37.  
  38. Return value    modf returns the fractional part of value.
  39.  
  40. *---------------------------------------------------------------------------*/
  41. #pragma warn -rvl
  42. double    modf (double value, double *wholeP)
  43. {
  44. asm    FLD    DOUBLE (value)
  45.  
  46. asm    mov    ax, value [6]
  47. asm    shl    ax, 1
  48. asm    cmp    ax, 0FFE0h        /* infinite exponent ?    */
  49. asm    jnb    mdf_infinite
  50.  
  51. asm    FLD    st(0)            /* duplicate ST */
  52.  
  53. asm    push    ax            /* make a word on the stack    */
  54. asm    mov    bx, sp
  55.  
  56. asm    FSTCW    W0 (SS_ [bx])        /* read out the current control word */
  57. asm    mov    ax, 0F3FFh
  58. asm    FWAIT
  59. asm    and    ax, SS_ [bx]        /* mask out the rounding control */
  60. asm    or    ah, 0Ch            /* chop towards zero    */
  61. asm    push    ax
  62. asm    FLDCW    W0 (SS_ [bx-2])
  63. asm    pop    ax
  64.  
  65. asm    FRNDINT                /* round to integer    */
  66.  
  67. asm    FLDCW    W0 (SS_ [bx])        /* restore original rounding control */
  68. asm    pop    ax
  69.  
  70. asm    LES_    bx, wholeP
  71. asm    FST    DOUBLE (ES_ [bx])    /* *wholeP = chop (value)    */
  72.  
  73. asm    FSUBP    st(1), st        /* fraction = value - chop(value) */
  74.  
  75. mdf_end:
  76.     return;
  77.  
  78. mdf_infinite:                /* infinity == rounded (infinity) */
  79. asm    LES_    bx, wholeP
  80. asm    FSTP    DOUBLE (ES_ [bx])
  81. asm    FLDZ                /* zero = infinity - infinity    */
  82. asm    jmp    short    mdf_end
  83. }
  84. #pragma warn .rvl
  85.