home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 1.ddi / MATHSRC.ZIP / MODF.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.9 KB  |  70 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - modf.cas
  3.  *
  4.  * function(s)
  5.  *        modf - splits into mantissa and exponent
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19.  
  20. #include <_math.h>
  21. #include <math.h>
  22.  
  23.  
  24. /*--------------------------------------------------------------------------*
  25.  
  26. Name            modf - splits into mantissa and exponent
  27.  
  28. Usage           double  modf(double value, double *wholeP);
  29.  
  30. Prototype in    math.h
  31.  
  32. Description     modf breaks  the double value  into two parts:  the integer
  33.                 and  the fraction.  It stores   the integer  in wholeP  and
  34.                 returns the fraction.
  35.  
  36. Return value    modf returns the fractional part of value.
  37.  
  38. *---------------------------------------------------------------------------*/
  39. #pragma warn -rvl
  40.  
  41. double _FARFUNC modf( double value, double *wholeP )
  42. {
  43. asm     FLD     DOUBLE (value)
  44.  
  45. asm     mov     ax, value [6]
  46. asm     shl     ax, 1
  47. asm     cmp     ax, 0FFE0h              /* infinite exponent ?  */
  48. asm     jnb     mdf_infinite
  49.  
  50. asm     FLD     st(0)                   /* duplicate ST */
  51.  
  52. asm     mov     ch, 0Ch                 /* chop towards zero    */
  53.         __round();
  54.  
  55. asm     LES_    bx, wholeP
  56. asm     FST     DOUBLE (ES_ [bx])       /* *wholeP = chop (value)       */
  57.  
  58. asm     FSUBP   st(1), st               /* fraction = value - chop(value) */
  59.  
  60. mdf_end:
  61.         return;
  62.  
  63. mdf_infinite:                           /* infinity == rounded (infinity) */
  64. asm     LES_    bx, wholeP
  65. asm     FSTP    DOUBLE (ES_ [bx])
  66. asm     FLDZ                            /* zero = infinity - infinity   */
  67. asm     jmp     short   mdf_end
  68. }
  69. #pragma warn .rvl
  70.