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

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