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

  1. /*------------------------------------------------------------------------
  2.  * filename - coshl.cas
  3.  *
  4.  * function(s)
  5.  *        coshl - long double hyperbolic cosine 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            coshl - long double hyperbolic function
  28.  
  29. Usage           long double coshl(long double x);
  30.  
  31. Prototype in    math.h
  32.  
  33. Description     coshl computes the hyperbolic cosine of the input value.
  34.  
  35. Return value    coshl returns the hyperbolic cosine of the input value.
  36.                 For  large arguments  (absolute value greater  than
  37.                 ~11356.5) the result  will be  _LHUGE_VAL of
  38.                 the appropriate sign and errno will be set to:
  39.                         ERANGE  Range error.
  40. e
  41. *---------------------------------------------------------------------------*/
  42. #pragma warn -rvl
  43. long double _FARFUNC coshl (long double  x)
  44. {
  45. asm     FLD1
  46. asm     mov     ax, 7FFFh
  47. asm     FCHS                    /* TOS = -1.0, used in FSCALE later */
  48. asm     and     ax, x [8]       /* select exponent */
  49.  
  50. asm     FLD     LONGDOUBLE (x)
  51. asm     cmp     ax, 3fffh+13
  52. asm     jae     coshl_tooBig    /* exp (+-2^13) considered too large */
  53. asm     cmp     ax, 3fffh-13
  54. asm     jb      coshl_tiny
  55.  
  56. coshl_justFits:
  57.         __expld();               /* TOS = expl(x) */
  58.  
  59. asm     FLD1
  60. asm     FDIV    st, st(1)       /* TOS = expl (-x) = 1 / expl(x) */
  61. asm     FADDP   st(1), st       /* TOS = expl(x) + expl(-x) */
  62. asm     FSCALE                  /* coshl (x) = (expl(x) + expl(-x)) / 2 */
  63. asm     FSTP    st(1)
  64.  
  65. coshl_end:
  66.         return;
  67.  
  68. coshl_tooBig:
  69. asm     mov     ax, 0FFFFh      /* force extreme */
  70. asm     ja      coshl_excess
  71. asm     mov     ax, x [6]
  72.  
  73. coshl_excess:
  74. asm     test    BY0 (x [9]), 80h
  75. asm     jnz     coshl_tooTiny
  76. asm     cmp     ax, 0B172h
  77. asm     jb      coshl_justFits
  78. asm     mov     si, OVERFLOW
  79. asm     jmp     short   coshl_err
  80.  
  81. coshl_tooTiny:
  82. asm     cmp     ax, 0B16Ch
  83. asm     jb      coshl_justFits
  84. asm     mov     si, UNDERFLOW
  85.  
  86. coshl_err:
  87. asm     FSTP    ST(0)                   /* pop two items off the stack */
  88. asm     FSTP    ST(0)
  89.  
  90. #pragma warn -ret
  91.         return  __matherrl (_SI, "coshl", &x, NULL,
  92.                           (UNDERFLOW == _SI) ? 0.0 : _LHUGE_VAL);
  93.  
  94. /*
  95.   coshl is more accurately calculated by the polynomial
  96.  
  97.         (1 + x^2/2)
  98.  
  99.   when x is tiny (|x| < 2^-13).
  100. */
  101. coshl_tiny:
  102. asm     FLD     LONGDOUBLE (x)
  103. asm     FMUL    ST(0), ST(0)
  104. asm     FSCALE                  /* divide by 2  */
  105. asm     FSUBRP  ST(1), ST(0)    /* +1 == - (-1) */
  106. asm     jmp     short   coshl_end
  107. }
  108. #pragma warn .rvl
  109.