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

  1. /*------------------------------------------------------------------------
  2.  * filename - modfl.cas
  3.  *
  4.  * function(s)
  5.  *        modfl - splits long double 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            modfl - splits long double into mantissa and exponent
  27.  
  28. Usage           long double  modfl(long double value, long double *wholeP);
  29.  
  30. Prototype in    math.h
  31.  
  32. Description     modfl breaks the long 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    modfl returns the fractional part of value.
  37.  
  38. *---------------------------------------------------------------------------*/
  39. #pragma warn -rvl
  40. long double _FARFUNC modfl (long double value, long double *wholeP)
  41. {
  42. asm     FLD     LONGDOUBLE (value)
  43.  
  44. asm     mov     ax, value [8]
  45. asm     shl     ax, 1
  46. asm     cmp     ax, 0FFFEh              /* infinite exponent ?  */
  47. asm     jnb     mdf_infinite
  48.  
  49. asm     FLD     st(0)                   /* duplicate ST */
  50. asm     mov     ch, 0Ch                 /* chop towards zero    */
  51.         __round();
  52. asm     FSUB    st(1), st               /* fraction = value - chop(value) */
  53. asm     LES_    bx, wholeP
  54. asm     FSTP    LONGDOUBLE (ES_ [bx])   /* *wholeP = chop (value)       */
  55.  
  56. mdf_end:
  57.         return;
  58.  
  59. mdf_infinite:                           /* infinity == rounded (infinity) */
  60. asm     LES_    bx, wholeP
  61. asm     FSTP    LONGDOUBLE (ES_ [bx])
  62. asm     FLDZ                            /* zero = infinity - infinity   */
  63. asm     jmp     short   mdf_end
  64. }
  65. #pragma warn .rvl
  66.