/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4851638 4939441
* @summary Tests for {Math, StrictMath}.log1p
* @author Joseph D. Darcy
*/
public class Log1pTests {
private Log1pTests(){}
/**
* Formulation taken from HP-15C Advanced Functions Handbook, part
* number HP 0015-90011, p 181. This is accurate to a few ulps.
*/
static double hp15cLogp(double x) {
double u = 1.0 + x;
}
/*
* The Taylor expansion of ln(1 + x) for -1 < x <= 1 is:
*
* x - x^2/2 + x^3/3 - ... -(-x^j)/j
*
* Therefore, for small values of x, log1p(x) ~= x. For large
* values of x, log1p(x) ~= log(x).
*
* Also x/(x+1) < ln(1+x) < x
*/
static int testLog1p() {
int failures = 0;
double [][] testCases = {
{-8.0, NaNd},
{-1.0, -infinityD},
{-0.0, -0.0},
{+0.0, +0.0},
};
// Test special cases
}
// For |x| < 2^-54 log1p(x) ~= x
failures += testLog1pCase(d, d);
failures += testLog1pCase(-d, -d);
}
// For x > 2^53 log1p(x) ~= log(x)
}
// Construct random values with exponents ranging from -53 to
// 52 and compare against HP-15C formula.
for(int i = 0; i < 1000; i++) {
double d = rand.nextDouble();
for(int j = -53; j <= 52; j++) {
d *= 2.0; // increase exponent by 1
}
}
// Test for monotonicity failures near values y-1 where y ~=
// e^x. Test two numbers before and two numbers after each
// chosen value; i.e.
//
// pcNeighbors[] =
// {nextDown(nextDown(pc)),
// nextDown(pc),
// pc,
// nextUp(pc),
// nextUp(nextUp(pc))}
//
// and we test that log1p(pcNeighbors[i]) <= log1p(pcNeighbors[i+1])
{
double pcNeighbors[] = new double[5];
double pcNeighborsLog1p[] = new double[5];
double pcNeighborsStrictLog1p[] = new double[5];
for(int i = -36; i <= 36; i++) {
}
failures++;
pcNeighbors[j] + " and " +
pcNeighborsLog1p[j] + " and " +
pcNeighborsLog1p[j+1] );
}
failures++;
pcNeighbors[j] + " and " +
pcNeighborsStrictLog1p[j] + " and " +
pcNeighborsStrictLog1p[j+1] );
}
}
}
}
return failures;
}
double expected) {
}
double expected,
double ulps) {
int failures = 0;
return failures;
}
int failures = 0;
if (failures > 0) {
+ failures + " failures.");
throw new RuntimeException();
}
}
}