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

  1. /*------------------------------------------------------------------------
  2.  * filename - cosh.cas
  3.  *
  4.  * function(s)
  5.  *        cosh - hyperbolic 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.  
  28. Name            cosh - hyperbolic function
  29.  
  30. Usage           double cosh(double x);
  31.  
  32. Prototype in    math.h
  33.  
  34. Description     cosh computes the hyperbolic cosine of the input value.
  35.  
  36. Return value    cosh returns the hyperbolic cosine of the input value.
  37.                 For  large arguments  (magnitude greater  than or  equal to
  38.                 710.475)  the result  will be  HUGE_VAL of  the appropriate
  39.                 sign and errno will be set to:
  40.                         ERANGE  Range error.
  41.  
  42. *---------------------------------------------------------------------------*/
  43. #pragma warn -rvl
  44.  
  45. double _FARFUNC cosh( double  x )
  46. {
  47. asm     FLD1
  48. asm     mov     ax, 7FFFh
  49. asm     FCHS                    /* TOS = -1.0   */
  50. asm     and     ax, x [6]       /* select exponent and most signif. bits */
  51.  
  52. asm     FLD     DOUBLE (x)
  53. asm     cmp     ax, 4086h
  54. asm     jnb     cosh_tooBig     /* exp (+-710.475) considered too large */
  55. asm     cmp     ax, 3F20h
  56. asm     jb      cosh_tiny
  57. cosh_justFits:
  58.  
  59. #ifdef _Windows
  60.         _f87_Exp();
  61. #else
  62. asm     _FAST_  (_FEXP_)
  63. #endif
  64.  
  65. asm     FLD1
  66. asm     FDIV    st, st(1)       /* Exp (-x) */
  67. asm     FADDP   st(1), st
  68. asm     FSCALE                  /* cosh (x) = (exp(x) + exp(-x)) / 2 */
  69. asm     FSTP    st(1)
  70.  
  71. cosh_end:
  72.         return;
  73.  
  74. cosh_tooBig:
  75. asm     ja      cosh_over
  76. asm     cmp     W0 (x [4]), 033CEh
  77. asm     jb      cosh_justFits
  78.  
  79. cosh_over:
  80.  
  81. asm     FSTP    ST(0)                   /* pop two items off the stack */
  82. asm     FSTP    ST(0)
  83.  
  84. #pragma warn -ret
  85.         return _matherr (OVERFLOW, "cosh", &x, NULL, HUGE_VAL);
  86. #pragma warn .ret
  87.  
  88. /*
  89.   cosh is more accurately calculated by the polynomial
  90.  
  91.         (1 + x^2/2)
  92.  
  93.   when x is tiny (|x| < 2^-13).
  94. */
  95. cosh_tiny:
  96. asm     FMUL    ST(0), ST(0)
  97. asm     FSCALE                  /* divide by 2  */
  98. asm     FSUBRP  ST(1), ST(0)    /* +1 == - (-1) */
  99. asm     jmp     short   cosh_end
  100. }
  101. #pragma warn .rvl
  102.