home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / MATHSRC.ZIP / FREXPL.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.1 KB  |  76 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - frexpl.cas
  3.  *
  4.  * function(s)
  5.  *        frexpl - splits a long double number 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. Name            frexpl - splits a long double number into mantissa and exponent
  26.  
  27. Usage           long double frexpl(long double value, int *expP);
  28.  
  29. Prototype in    math.h
  30.  
  31. Description     Split  a  floating  point  number  into  its  exponent  and
  32.                 fractional parts, with the  exponent placed into *expP, and
  33.                 the fraction is the function return value.
  34.  
  35. Return value    frexpl returns  value - (*expP = chop (value));
  36.  
  37. *---------------------------------------------------------------------------*/
  38. #pragma warn -rvl
  39. long double _FARFUNC frexpl (long double value, int *expP)
  40. {
  41.         volatile unsigned statword;
  42. asm     FLD     LONGDOUBLE (value)
  43.  
  44. asm     LES_    bx, expP
  45. asm     mov     W0 (ES_ [bx]), 0
  46.  
  47. /* if value was +-0, return it */
  48. asm     FTST
  49. asm     FSTSW   statword
  50. asm     FWAIT
  51. asm     mov     ah, BY1(statword)
  52. asm     sahf
  53. asm     jz      done
  54.  
  55. asm     FXTRACT                 /* ST(1) = exponent, (pushed) ST = fraction */
  56. asm     FXCH
  57.  
  58. /*
  59.   The FXTRACT instruction normalizes the fraction 1 bit higher than
  60.   wanted for the definition of frexpl() so we need to tweak the result
  61.   by scaling the fraction down and incrementing the exponent.
  62. */
  63.  
  64. asm     FISTP   W0 (ES_ [bx])
  65. asm     FLD1
  66. asm     FCHS
  67. asm     FXCH
  68. asm     FSCALE                  /* fraction scaled as C expects */
  69. asm     inc     W0 (ES_ [bx])   /* exponent biased to match     */
  70. asm     FSTP    ST(1)           /* discard -1, leave fraction as TOS */
  71.  
  72. done:
  73.         return;
  74. }
  75. #pragma warn .rvl
  76.