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

  1. /*------------------------------------------------------------------------
  2.  * filename - expl.cas
  3.  *
  4.  * function(s)
  5.  *        expl - long double 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            expl - exponential function
  28.  
  29. Usage           long double expl(long double x);
  30.  
  31. Prototype in    math.h
  32.  
  33. Description     expl calculates the exponent of x. For large arguments
  34.                 (absolute value greater than or equal to ~11356.5 ) the result
  35.                 an overflow to infinity or an underflow to zero, and
  36.                 _matherrl will be called.
  37.  
  38.  
  39. Return value    expl returns the exponent of x.  For large arguments
  40.                 (absolute value greater than or equal to ~11356.5 ) the result
  41.                 will be an overflow to infinity or an underflow to zero.
  42.  
  43. *---------------------------------------------------------------------------*/
  44. #pragma warn -rvl
  45. #pragma warn -ret
  46. long double _FARFUNC expl (long double x)
  47. {
  48. asm     FLD     LONGDOUBLE (x)
  49. asm     mov     ax, x [8]       /* select exponent */
  50. asm     and     ah, 7Fh         /* remove sign bit */
  51. asm     cmp     ax, 3fffh+13
  52. asm     jb      exp_OK          /* expl (+-2^13) is the limit for long double */
  53.  
  54. exp_tooBig:
  55. asm     mov     ax, 0FFFFh      /* force extreme */
  56. asm     ja      exp_excess
  57. asm     mov     ax, x [6]
  58.  
  59. exp_excess:
  60. asm     test    BY0 (x [9]), 80h
  61. asm     jnz     exp_tooTiny
  62. asm     cmp     ax, 0B172h
  63. asm     jb      exp_OK
  64. asm     mov     si, OVERFLOW
  65. asm     jmp     short   exp_err
  66.  
  67. exp_tooTiny:
  68. asm     cmp     ax, 0B16Ch
  69. asm     jb      exp_OK
  70. asm     mov     si, UNDERFLOW
  71.  
  72. exp_err:
  73. asm     FSTP    ST(0)           /* discard ST */
  74.         return  __matherrl (_SI, "expl", &x, NULL,
  75.                           (UNDERFLOW == _SI) ? 0.0 : _LHUGE_VAL);
  76. exp_OK:
  77.         __expld();
  78.         return;
  79. }
  80. #pragma warn .ret
  81. #pragma warn .rvl
  82.