11.1Schristos/* $NetBSD: n_atanhf.c,v 1.1 2016/09/21 14:11:40 christos Exp $ */ 21.1Schristos/* 31.1Schristos * Copyright (c) 1985, 1993 41.1Schristos * The Regents of the University of California. All rights reserved. 51.1Schristos * 61.1Schristos * Redistribution and use in source and binary forms, with or without 71.1Schristos * modification, are permitted provided that the following conditions 81.1Schristos * are met: 91.1Schristos * 1. Redistributions of source code must retain the above copyright 101.1Schristos * notice, this list of conditions and the following disclaimer. 111.1Schristos * 2. Redistributions in binary form must reproduce the above copyright 121.1Schristos * notice, this list of conditions and the following disclaimer in the 131.1Schristos * documentation and/or other materials provided with the distribution. 141.1Schristos * 3. Neither the name of the University nor the names of its contributors 151.1Schristos * may be used to endorse or promote products derived from this software 161.1Schristos * without specific prior written permission. 171.1Schristos * 181.1Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 191.1Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 201.1Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 211.1Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 221.1Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 231.1Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 241.1Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 251.1Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 261.1Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 271.1Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 281.1Schristos * SUCH DAMAGE. 291.1Schristos */ 301.1Schristos#include <sys/cdefs.h> 311.1Schristos__RCSID("$NetBSD: n_atanhf.c,v 1.1 2016/09/21 14:11:40 christos Exp $"); 321.1Schristos 331.1Schristos#ifndef lint 341.1Schristos#if 0 351.1Schristosstatic char sccsid[] = "@(#)atanh.c 8.1 (Berkeley) 6/4/93"; 361.1Schristos#endif 371.1Schristos#endif /* not lint */ 381.1Schristos 391.1Schristos/* ATANH(X) 401.1Schristos * RETURN THE HYPERBOLIC ARC TANGENT OF X 411.1Schristos * DOUBLE PRECISION (VAX D format 56 bits, IEEE DOUBLE 53 BITS) 421.1Schristos * CODED IN C BY K.C. NG, 1/8/85; 431.1Schristos * REVISED BY K.C. NG on 2/7/85, 3/7/85, 8/18/85. 441.1Schristos * 451.1Schristos * Required kernel function: 461.1Schristos * log1p(x) ...return log(1+x) 471.1Schristos * 481.1Schristos * Method : 491.1Schristos * Return 501.1Schristos * 1 2x x 511.1Schristos * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) 521.1Schristos * 2 1 - x 1 - x 531.1Schristos * 541.1Schristos * Special cases: 551.1Schristos * atanh(x) is NaN if |x| > 1 with signal; 561.1Schristos * atanh(NaN) is that NaN with no signal; 571.1Schristos * atanh(+-1) is +-INF with signal. 581.1Schristos * 591.1Schristos * Accuracy: 601.1Schristos * atanh(x) returns the exact hyperbolic arc tangent of x nearly rounded. 611.1Schristos * In a test run with 512,000 random arguments on a VAX, the maximum 621.1Schristos * observed error was 1.87 ulps (units in the last place) at 631.1Schristos * x= -3.8962076028810414000e-03. 641.1Schristos */ 651.1Schristos#include "mathimpl.h" 661.1Schristos 671.1Schristos#if defined(__vax__)||defined(tahoe) 681.1Schristos#include <errno.h> 691.1Schristos#endif /* defined(__vax__)||defined(tahoe) */ 701.1Schristos 711.1Schristosfloat 721.1Schristosatanhf(float x) 731.1Schristos{ 741.1Schristos float z; 751.1Schristos z = copysignf(0.5,x); 761.1Schristos x = copysignf(x,1.0); 771.1Schristos#if defined(__vax__)||defined(tahoe) 781.1Schristos if (x == 1.0) { 791.1Schristos return(copysignf(1.0,z)*infnan(ERANGE)); /* sign(x)*INF */ 801.1Schristos } 811.1Schristos#endif /* defined(__vax__)||defined(tahoe) */ 821.1Schristos x = x/(1.0-x); 831.1Schristos return( z*log1pf(x+x) ); 841.1Schristos} 85