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

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