Skip to content

Commit dfce4e1

Browse files
committed
8302800: Augment NaN handling tests of FDLIBM methods
Reviewed-by: bpb
1 parent 5489c82 commit dfce4e1

File tree

7 files changed

+119
-104
lines changed

7 files changed

+119
-104
lines changed

test/jdk/java/lang/Math/CubeRootTests.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,13 +25,15 @@
2525
* @test
2626
* @library /test/lib
2727
* @build jdk.test.lib.RandomFactory
28+
* @build Tests
2829
* @run main CubeRootTests
2930
* @bug 4347132 4939441 8078672
3031
* @summary Tests for {Math, StrictMath}.cbrt (use -Dseed=X to set PRNG seed)
3132
* @key randomness
3233
*/
3334

3435
import jdk.test.lib.RandomFactory;
36+
import static java.lang.Double.longBitsToDouble;
3537

3638
public class CubeRootTests {
3739
private CubeRootTests(){}
@@ -42,7 +44,7 @@ private CubeRootTests(){}
4244
// Initialize shared random number generator
4345
static java.util.Random rand = RandomFactory.getRandom();
4446

45-
static int testCubeRootCase(double input, double expected) {
47+
private static int testCubeRootCase(double input, double expected) {
4648
int failures=0;
4749

4850
failures+=Tests.test("Math.cbrt", input, Math::cbrt, expected);
@@ -53,22 +55,17 @@ static int testCubeRootCase(double input, double expected) {
5355
return failures;
5456
}
5557

56-
static int testCubeRoot() {
58+
private static int testCubeRoot() {
5759
int failures = 0;
60+
61+
for(double nan : Tests.NaNs) {
62+
failures += testCubeRootCase(nan, NaNd);
63+
}
64+
5865
double [][] testCases = {
59-
{NaNd, NaNd},
60-
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
61-
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
62-
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
63-
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
64-
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
65-
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
66-
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
67-
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
68-
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
69-
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
7066
{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY},
7167
{Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY},
68+
7269
{+0.0, +0.0},
7370
{-0.0, -0.0},
7471
{+1.0, +1.0},

test/jdk/java/lang/Math/Expm1Tests.java

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,9 +24,14 @@
2424
/*
2525
* @test
2626
* @bug 4851638 4900189 4939441
27+
* @build Tests
28+
* @build Expm1Tests
29+
* @run main Expm1Tests
2730
* @summary Tests for {Math, StrictMath}.expm1
2831
*/
2932

33+
import static java.lang.Double.longBitsToDouble;
34+
3035
/*
3136
* The Taylor expansion of expxm1(x) = exp(x) -1 is
3237
*
@@ -48,21 +53,14 @@ private Expm1Tests(){}
4853
static final double infinityD = Double.POSITIVE_INFINITY;
4954
static final double NaNd = Double.NaN;
5055

51-
static int testExpm1() {
56+
private static int testExpm1() {
5257
int failures = 0;
5358

59+
for(double nan : Tests.NaNs) {
60+
failures += testExpm1Case(nan, NaNd);
61+
}
62+
5463
double [][] testCases = {
55-
{Double.NaN, NaNd},
56-
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
57-
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
58-
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
59-
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
60-
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
61-
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
62-
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
63-
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
64-
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
65-
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
6664
{infinityD, infinityD},
6765
{-infinityD, -1.0},
6866
{-0.0, -0.0},

test/jdk/java/lang/Math/HyperbolicTests.java

+18-34
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,9 +24,14 @@
2424
/*
2525
* @test
2626
* @bug 4851625 4900189 4939441
27+
* @build Tests
28+
* @build HyperbolicTests
29+
* @run main HyperbolicTests
2730
* @summary Tests for {Math, StrictMath}.{sinh, cosh, tanh}
2831
*/
2932

33+
import static java.lang.Double.longBitsToDouble;
34+
3035
public class HyperbolicTests {
3136
private HyperbolicTests(){}
3237

@@ -248,19 +253,12 @@ static int testSinh() {
248253
3.0);
249254
}
250255

256+
for(double nan : Tests.NaNs) {
257+
failures += testSinhCaseWithUlpDiff(nan, NaNd, 0);
258+
}
259+
251260
double [][] specialTestCases = {
252261
{0.0, 0.0},
253-
{NaNd, NaNd},
254-
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
255-
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
256-
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
257-
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
258-
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
259-
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
260-
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
261-
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
262-
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
263-
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
264262
{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}
265263
};
266264

@@ -590,19 +588,12 @@ static int testCosh() {
590588
3.0);
591589
}
592590

591+
for(double nan : Tests.NaNs) {
592+
failures += testCoshCaseWithUlpDiff(nan, NaNd, 0);
593+
}
594+
593595
double [][] specialTestCases = {
594596
{0.0, 1.0},
595-
{NaNd, NaNd},
596-
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
597-
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
598-
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
599-
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
600-
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
601-
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
602-
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
603-
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
604-
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
605-
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
606597
{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}
607598
};
608599

@@ -938,19 +929,12 @@ static int testTanh() {
938929
3.0);
939930
}
940931

932+
for(double nan : Tests.NaNs) {
933+
failures += testTanhCaseWithUlpDiff(nan, NaNd, 0);
934+
}
935+
941936
double [][] specialTestCases = {
942937
{0.0, 0.0},
943-
{NaNd, NaNd},
944-
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
945-
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
946-
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
947-
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
948-
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
949-
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
950-
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
951-
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
952-
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
953-
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
954938
{Double.POSITIVE_INFINITY, 1.0}
955939
};
956940

test/jdk/java/lang/Math/InverseTrigTests.java

+20-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
* @summary Tests for {Math, StrictMath}.{asin, acos, atan}
3131
*/
3232

33+
import static java.lang.Double.longBitsToDouble;
34+
3335
public class InverseTrigTests {
3436
private InverseTrigTests(){}
3537

@@ -64,8 +66,11 @@ public static void main(String... args) {
6466
private static int testAsinSpecialCases() {
6567
int failures = 0;
6668

69+
for(double nan : Tests.NaNs) {
70+
failures += testAsinCase(nan, NaNd);
71+
}
72+
6773
double [][] testCases = {
68-
{NaNd, NaNd},
6974
{Math.nextUp(1.0), NaNd},
7075
{Math.nextDown(-1.0), NaNd},
7176
{ InfinityD, NaNd},
@@ -86,8 +91,8 @@ private static int testAsinSpecialCases() {
8691
private static int testAsinCase(double input, double expected) {
8792
int failures=0;
8893

89-
failures+=Tests.test("Math.asin", input, Math::asin, expected);
90-
failures+=Tests.test("StrictMath.asin", input, StrictMath::asin, expected);
94+
failures += Tests.test("Math.asin", input, Math::asin, expected);
95+
failures += Tests.test("StrictMath.asin", input, StrictMath::asin, expected);
9196

9297
return failures;
9398
}
@@ -105,8 +110,11 @@ private static int testAsinCase(double input, double expected) {
105110
private static int testAcosSpecialCases() {
106111
int failures = 0;
107112

113+
for(double nan : Tests.NaNs) {
114+
failures += testAcosCase(nan, NaNd);
115+
}
116+
108117
double [][] testCases = {
109-
{NaNd, NaNd},
110118
{Math.nextUp(1.0), NaNd},
111119
{Math.nextDown(-1.0), NaNd},
112120
{InfinityD, NaNd},
@@ -126,8 +134,8 @@ private static int testAcosSpecialCases() {
126134
private static int testAcosCase(double input, double expected) {
127135
int failures=0;
128136

129-
failures+=Tests.test("Math.acos", input, Math::acos, expected);
130-
failures+=Tests.test("StrictMath.acos", input, StrictMath::acos, expected);
137+
failures += Tests.test("Math.acos", input, Math::acos, expected);
138+
failures += Tests.test("StrictMath.acos", input, StrictMath::acos, expected);
131139

132140
return failures;
133141
}
@@ -148,9 +156,11 @@ private static int testAcosCase(double input, double expected) {
148156
private static int testAtanSpecialCases() {
149157
int failures = 0;
150158

151-
double [][] testCases = {
152-
{NaNd, NaNd},
159+
for(double nan : Tests.NaNs) {
160+
failures += testAtanCase(nan, NaNd);
161+
}
153162

163+
double [][] testCases = {
154164
{-0.0, -0.0},
155165
{+0.0, +0.0},
156166

@@ -169,8 +179,8 @@ private static int testAtanSpecialCases() {
169179
private static int testAtanCase(double input, double expected) {
170180
int failures=0;
171181

172-
failures+=Tests.test("Math.atan", input, Math::atan, expected);
173-
failures+=Tests.test("StrictMath.atan", input, StrictMath::atan, expected);
182+
failures += Tests.test("Math.atan", input, Math::atan, expected);
183+
failures += Tests.test("StrictMath.atan", input, StrictMath::atan, expected);
174184

175185
return failures;
176186
}

test/jdk/java/lang/Math/Log10Tests.java

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,43 +24,41 @@
2424
/*
2525
* @test
2626
* @bug 4074599 4939441
27+
* @build Tests
28+
* @build Log10Tests
29+
* @run main Log10Tests
2730
* @summary Tests for {Math, StrictMath}.log10
2831
*/
2932

33+
import static java.lang.Double.longBitsToDouble;
34+
3035
public class Log10Tests {
3136
private Log10Tests(){}
3237

33-
static final double infinityD = Double.POSITIVE_INFINITY;
34-
static final double NaNd = Double.NaN;
35-
static final double LN_10 = StrictMath.log(10.0);
38+
private static final double infinityD = Double.POSITIVE_INFINITY;
39+
private static final double NaNd = Double.NaN;
40+
private static final double LN_10 = StrictMath.log(10.0);
3641

3742
// Initialize shared random number generator
3843
static java.util.Random rand = new java.util.Random(0L);
3944

40-
static int testLog10Case(double input, double expected) {
45+
private static int testLog10Case(double input, double expected) {
4146
int failures=0;
4247

43-
failures+=Tests.test("Math.log10", input, Math::log10, expected);
44-
failures+=Tests.test("StrictMath.log10", input, StrictMath::log10, expected);
48+
failures += Tests.test("Math.log10", input, Math::log10, expected);
49+
failures += Tests.test("StrictMath.log10", input, StrictMath::log10, expected);
4550

4651
return failures;
4752
}
4853

49-
static int testLog10() {
54+
private static int testLog10() {
5055
int failures = 0;
5156

57+
for(double nan : Tests.NaNs) {
58+
failures += testLog10Case(nan, NaNd);
59+
}
60+
5261
double [][] testCases = {
53-
{Double.NaN, NaNd},
54-
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
55-
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
56-
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
57-
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
58-
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
59-
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
60-
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
61-
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
62-
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
63-
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
6462
{Double.NEGATIVE_INFINITY, NaNd},
6563
{-8.0, NaNd},
6664
{-1.0, NaNd},

test/jdk/java/lang/Math/Log1pTests.java

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@
2525
* @test
2626
* @library /test/lib
2727
* @build jdk.test.lib.RandomFactory
28+
* @build Tests
29+
* @build Log1pTests
2830
* @run main Log1pTests
2931
* @bug 4851638 4939441 8078672
3032
* @summary Tests for {Math, StrictMath}.log1p (use -Dseed=X to set PRNG seed)
@@ -59,21 +61,14 @@ static double hp15cLogp(double x) {
5961
* Also x/(x+1) < ln(1+x) < x
6062
*/
6163

62-
static int testLog1p() {
64+
private static int testLog1p() {
6365
int failures = 0;
6466

67+
for(double nan : Tests.NaNs) {
68+
failures += testLog1pCase(nan, NaNd);
69+
}
70+
6571
double [][] testCases = {
66-
{Double.NaN, NaNd},
67-
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
68-
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
69-
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
70-
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
71-
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
72-
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
73-
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
74-
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
75-
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
76-
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
7772
{Double.NEGATIVE_INFINITY, NaNd},
7873
{-8.0, NaNd},
7974
{-1.0, -infinityD},

0 commit comments

Comments
 (0)