tanhl.c revision 61ec6b12089c560a32ebd9efdbb057ff92665e60
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 2N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A * tanhl(x) returns the hyperbolic tangent of x 2N/A * 1. reduce x to non-negative: tanhl(-x) = - tanhl(x). 2N/A * 0 < x <= small : tanhl(x) := x 2N/A * small < x <= 1 : tanhl(x) := -------------- 2N/A * 1 <= x <= threshold : tanhl(x) := 1 - --------------- 2N/A * threshold < x <= INF : tanhl(x) := 1. 2N/A * single : small = 1.e-5 threshold = 11.0 2N/A * double : small = 1.e-10 threshold = 22.0 2N/A * quad : small = 1.e-20 threshold = 45.0 2N/A * Note: threshold was chosen so that 2N/A * fl(1.0+2/(expm1(2*threshold)+2)) == 1. 2N/A * tanhl(NaN) is NaN; 2N/A * only tanhl(0.0)=0.0 is exact for finite argument. 2N/A long double t, y, z;
2N/A return (x + x);
/* x is NaN */ 2N/A /* inexact if t != 0 */