home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / g / gnu_c / pmlsrc23.zoo / pmlsrc / acosh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-19  |  2.5 KB  |  108 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *                N O T I C E                *
  4.  *                                    *
  5.  *            Copyright Abandoned, 1987, Fred Fish        *
  6.  *                                    *
  7.  *    This previously copyrighted work has been placed into the    *
  8.  *    public domain by the author (Fred Fish) and may be freely used    *
  9.  *    for any purpose, private or commercial.  I would appreciate    *
  10.  *    it, as a courtesy, if this notice is left in all copies and    *
  11.  *    derivative works.  Thank you, and enjoy...            *
  12.  *                                    *
  13.  *    The author makes no warranty of any kind with respect to this    *
  14.  *    product and explicitly disclaims any implied warranties of    *
  15.  *    merchantability or fitness for any particular purpose.        *
  16.  *                                    *
  17.  ************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  *  FUNCTION
  23.  *
  24.  *    acosh   double precision hyperbolic arc cosine
  25.  *
  26.  *  KEY WORDS
  27.  *
  28.  *    acosh
  29.  *    machine independent routines
  30.  *    math libraries
  31.  *
  32.  *  DESCRIPTION
  33.  *
  34.  *    Returns double precision hyperbolic arc cosine of double precision
  35.  *    floating point number.
  36.  *
  37.  *  USAGE
  38.  *
  39.  *    double acosh (x)
  40.  *    double x;
  41.  *
  42.  *  RESTRICTIONS
  43.  *
  44.  *    The range of the ACOSH function is all real numbers greater
  45.  *    than or equal to 1.0 however large arguments may cause
  46.  *    overflow in the x squared portion of the function evaluation.
  47.  *
  48.  *    For precision information refer to documentation of the
  49.  *    floating point library primatives called.
  50.  *    
  51.  *  PROGRAMMER
  52.  *
  53.  *    Fred Fish
  54.  *
  55.  *  INTERNALS
  56.  *
  57.  *    Computes acosh(x) from:
  58.  *
  59.  *        1.    If x < 1.0 then report illegal
  60.  *            argument and return zero.
  61.  *
  62.  *        2.    If x > sqrt(MAXDOUBLE) then
  63.  *            set x = sqrt(MAXDOUBLE and
  64.  *            continue after reporting overflow.
  65.  *
  66.  *        3.    acosh(x) = log [x+sqrt(x**2 - 1)]
  67.  *
  68.  */
  69. #if defined (__M68881__) && !defined (_M68881)
  70. /*# define _M68881*/    /* use the inline code for the internal math    */
  71. #endif
  72.  
  73. #include <stdio.h>
  74. #include <math.h>
  75. #include "pml.h"
  76.  
  77. static char funcname[] = "acosh";
  78.     struct exception xcpt;
  79.  
  80. double acosh (x)
  81. double x;
  82. {
  83.     if (x < 1.0) {
  84.     xcpt.type = DOMAIN;
  85.     xcpt.name = funcname;
  86.     xcpt.arg1 = x;
  87.     if (!matherr (&xcpt)) {
  88.         fprintf (stderr, "%s: DOMAIN error\n", funcname);
  89.         errno = ERANGE;
  90.         xcpt.retval = HUGE_VAL;
  91.     }
  92.     } else if (x > SQRT_MAXDOUBLE) {
  93.     xcpt.type = OVERFLOW;
  94.     xcpt.name = funcname;
  95.     xcpt.arg1 = x;
  96.     if (!matherr (&xcpt)) {
  97.         fprintf (stderr, "%s: OVERFLOW error\n", funcname);
  98.         errno = ERANGE;
  99.         x = SQRT_MAXDOUBLE;
  100.         xcpt.retval = log (2* SQRT_MAXDOUBLE);
  101.     }
  102.     } else {
  103.     xcpt.retval = log (x + sqrt (x*x - 1.0));
  104.     }
  105.     return (xcpt.retval);
  106. }
  107.  
  108.