2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 809N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 809N/A * This code is free software; you can redistribute it and/or modify it 809N/A * under the terms of the GNU General Public License version 2 only, as 809N/A * published by the Free Software Foundation. 809N/A * This code is distributed in the hope that it will be useful, but WITHOUT 809N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 809N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 809N/A * version 2 for more details (a copy is included in the LICENSE file that 809N/A * accompanied this code). 809N/A * You should have received a copy of the GNU General Public License version 809N/A * 2 along with this work; if not, write to the Free Software Foundation, 809N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 809N/A * @bug 4851638 4900189 4939441 809N/A * @summary Tests for {Math, StrictMath}.expm1 809N/A * @author Joseph D. Darcy 809N/A * The Taylor expansion of expxm1(x) = exp(x) -1 is 809N/A * 1 + x/1! + x^2/2! + x^3/3| + ... -1 = 809N/A * x + x^2/2! + x^3/3 + ... 809N/A * Therefore, for small values of x, expxm1 ~= x. 809N/A * For large values of x, expxm1(x) ~= exp(x) 809N/A * For large negative x, expxm1(x) ~= -1. 809N/A // For |x| < 2^-54 expm1(x) ~= x 809N/A // For values of y where exp(y) > 2^54, expm1(x) ~= exp(x). 809N/A // The least such y is ln(2^54) ~= 37.42994775023705; exp(x) 809N/A // overflows for x > ~= 709.8 809N/A // Use a 2-ulp error threshold to account for errors in the 809N/A // exp implementation; the increments of d in the loop will be 809N/A for(
double d =
37.5; d <=
709.5; d +=
1.0) {
809N/A // For x > 710, expm1(x) should be infinity 809N/A // By monotonicity, once the limit is reached, the 809N/A // implemenation should return the limit for all smaller 809N/A // Once exp(y) < 0.5 * ulp(1), expm1(y) ~= -1.0; 809N/A // The greatest such y is ln(2^-53) ~= -36.7368005696771. 809N/A for(
double d = -
36.75; d >= -
127.75; d -=
1.0) {
809N/A // Test for monotonicity failures near multiples of log(2). 809N/A // Test two numbers before and two numbers after each chosen 809N/A // {nextDown(nextDown(pc)), 809N/A // and we test that expm1(pcNeighbors[i]) <= expm1(pcNeighbors[i+1]) 809N/A for(
int i = -
50; i <=
50; i++) {