Log1pTests.java revision 809
809N/A * Copyright 2003 Sun Microsystems, Inc. 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. 809N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 809N/A * CA 95054 USA or visit www.sun.com if you need additional information or 809N/A * @summary Tests for {Math, StrictMath}.log1p 809N/A * @author Joseph D. Darcy 809N/A * Formulation taken from HP-15C Advanced Functions Handbook, part 809N/A * number HP 0015-90011, p 181. This is accurate to a few ulps. 809N/A * The Taylor expansion of ln(1 + x) for -1 < x <= 1 is: 809N/A * x - x^2/2 + x^3/3 - ... -(-x^j)/j 809N/A * Therefore, for small values of x, log1p(x) ~= x. For large 809N/A * values of x, log1p(x) ~= log(x). 809N/A * Also x/(x+1) < ln(1+x) < x 809N/A // For |x| < 2^-54 log1p(x) ~= x 809N/A // For x > 2^53 log1p(x) ~= log(x) 809N/A // Construct random values with exponents ranging from -53 to 809N/A // 52 and compare against HP-15C formula. 809N/A for(
int i =
0; i <
1000; i++) {
809N/A for(
int j = -
53; j <=
52; j++) {
809N/A d *=
2.0;
// increase exponent by 1 809N/A // Test for monotonicity failures near values y-1 where y ~= 809N/A // e^x. Test two numbers before and two numbers after each 809N/A // {nextDown(nextDown(pc)), 809N/A // and we test that log1p(pcNeighbors[i]) <= log1p(pcNeighbors[i+1]) 809N/A for(
int i = -
36; i <=
36; i++) {