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

  1. /*------------------------------------------------------------------------
  2.  * filename - exp.cas
  3.  *
  4.  * function(s)
  5.  *        exp - exponential function
  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. #include <errno.h>
  23. #include <stddef.h>
  24.  
  25. /*--------------------------------------------------------------------------*
  26.  
  27. Name            exp - exponential function
  28.  
  29. Usage           double exp(double x);
  30.  
  31. Prototype in    math.h
  32.  
  33. Description     exp calculates the exponent of x. For large exponents
  34.                 (magnitude greater than or equal to 709) the result will be
  35.                 an overflow to infinity or an underflow to zero.
  36.  
  37.  
  38. Return value    exp returns the exponent of x.  For large exponents
  39.                 (magnitude greater than or equal to 709) the result will be
  40.                 an overflow to infinity or an underflow to zero.
  41.  
  42. *---------------------------------------------------------------------------*/
  43. #pragma warn -rvl
  44.  
  45. double _FARFUNC exp( double x )
  46. {
  47. asm     FLD     DOUBLE (x)
  48. asm     mov     ax, 7FFFh
  49. asm     and     ax, x [6]       /* select exponent and most signif. bits */
  50. asm     cmp     ax, 4086h
  51. asm     jnb     exp_tooBig      /* exp (+-709) is the limit for double */
  52.  
  53. exp_justFits:
  54.  
  55. #ifdef _Windows
  56.         _f87_Exp();
  57. #else
  58. asm     _FAST_  (_FEXP_)
  59. #endif
  60.  
  61.         return;
  62.  
  63. exp_tooBig:
  64. asm     mov     ax, 0FFFFh      /* force extreme */
  65. asm     ja      exp_excess
  66. asm     mov     ax, x [4]
  67.  
  68. exp_excess:
  69. asm     test    BY0 (x [7]), 80h
  70. asm     jnz     exp_tooTiny
  71. asm     cmp     ax, 02E42h
  72. asm     jb      exp_justFits
  73. asm     mov     si, OVERFLOW
  74. asm     jmp     short   exp_err
  75.  
  76. exp_tooTiny:
  77. asm     cmp     ax, 0232Bh
  78. asm     jb      exp_justFits
  79. asm     mov     si, UNDERFLOW
  80.  
  81. exp_err:
  82. asm     FSTP    ST(0)           /* discard ST */
  83. #pragma warn -ret
  84.         return  _matherr (_SI, "exp", &x, NULL,
  85.                           (UNDERFLOW == _SI) ? 0.0 : HUGE_VAL);
  86. #pragma warn .ret
  87. }
  88. #pragma warn .rvl
  89.