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

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