|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1985 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: * ! 19: * All recipients should regard themselves as participants in an ongoing ! 20: * research project and hence should feel obligated to report their ! 21: * experiences (good or bad) with these elementary function codes, using ! 22: * the sendbug(8) program, to the authors. ! 23: */ ! 24: ! 25: #ifndef lint ! 26: static char sccsid[] = "@(#)atanh.c 5.5 (Berkeley) 6/1/90"; ! 27: #endif /* not lint */ ! 28: ! 29: /* ATANH(X) ! 30: * RETURN THE HYPERBOLIC ARC TANGENT OF X ! 31: * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) ! 32: * CODED IN C BY K.C. NG, 1/8/85; ! 33: * REVISED BY K.C. NG on 2/7/85, 3/7/85, 8/18/85. ! 34: * ! 35: * Required kernel function: ! 36: * log1p(x) ...return log(1+x) ! 37: * ! 38: * Method : ! 39: * Return ! 40: * 1 2x x ! 41: * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) ! 42: * 2 1 - x 1 - x ! 43: * ! 44: * Special cases: ! 45: * atanh(x) is NaN if |x| > 1 with signal; ! 46: * atanh(NaN) is that NaN with no signal; ! 47: * atanh(+-1) is +-INF with signal. ! 48: * ! 49: * Accuracy: ! 50: * atanh(x) returns the exact hyperbolic arc tangent of x nearly rounded. ! 51: * In a test run with 512,000 random arguments on a VAX, the maximum ! 52: * observed error was 1.87 ulps (units in the last place) at ! 53: * x= -3.8962076028810414000e-03. ! 54: */ ! 55: #include "mathimpl.h" ! 56: ! 57: #if defined(vax)||defined(tahoe) ! 58: #include <errno.h> ! 59: #endif /* defined(vax)||defined(tahoe) */ ! 60: ! 61: double atanh(x) ! 62: double x; ! 63: { ! 64: double z; ! 65: z = copysign(0.5,x); ! 66: x = copysign(x,1.0); ! 67: #if defined(vax)||defined(tahoe) ! 68: if (x == 1.0) { ! 69: return(copysign(1.0,z)*infnan(ERANGE)); /* sign(x)*INF */ ! 70: } ! 71: #endif /* defined(vax)||defined(tahoe) */ ! 72: x = x/(1.0-x); ! 73: return( z*log1p(x+x) ); ! 74: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.