author | jrose |
Sat, 05 Oct 2013 05:30:38 -0700 | |
changeset 20528 | 0b1e2130d3f7 |
parent 10608 | 7cfca36fc79b |
child 26197 | 1bb6b68b87cd |
permissions | -rw-r--r-- |
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
1 |
/* |
10608 | 2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
4 |
* |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
8 |
* |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
13 |
* accompanied this code). |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
14 |
* |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
22 |
*/ |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
23 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
24 |
/* |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
25 |
* @test |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
26 |
* @bug 6908131 |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
27 |
* @summary Check for correct implementation of Math.ceil and Math.floor |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
28 |
*/ |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
29 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
30 |
import sun.misc.DoubleConsts; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
31 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
32 |
public class CeilAndFloorTests { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
33 |
private static int testCeilCase(double input, double expected) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
34 |
int failures = 0; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
35 |
failures += Tests.test("Math.ceil", input, Math.ceil(input), expected); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
36 |
failures += Tests.test("StrictMath.ceil", input, StrictMath.ceil(input), expected); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
37 |
return failures; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
38 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
39 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
40 |
private static int testFloorCase(double input, double expected) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
41 |
int failures = 0; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
42 |
failures += Tests.test("Math.floor", input, Math.floor(input), expected); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
43 |
failures += Tests.test("StrictMath.floor", input, StrictMath.floor(input), expected); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
44 |
return failures; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
45 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
46 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
47 |
private static int nearIntegerTests() { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
48 |
int failures = 0; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
49 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
50 |
double [] fixedPoints = { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
51 |
-0.0, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
52 |
0.0, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
53 |
-1.0, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
54 |
1.0, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
55 |
-0x1.0p52, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
56 |
0x1.0p52, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
57 |
-Double.MAX_VALUE, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
58 |
Double.MAX_VALUE, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
59 |
Double.NEGATIVE_INFINITY, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
60 |
Double.POSITIVE_INFINITY, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
61 |
Double.NaN, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
62 |
}; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
63 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
64 |
for(double fixedPoint : fixedPoints) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
65 |
failures += testCeilCase(fixedPoint, fixedPoint); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
66 |
failures += testFloorCase(fixedPoint, fixedPoint); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
67 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
68 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
69 |
for(int i = Double.MIN_EXPONENT; i <= Double.MAX_EXPONENT; i++) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
70 |
double powerOfTwo = Math.scalb(1.0, i); |
10608 | 71 |
double neighborDown = Math.nextDown(powerOfTwo); |
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
72 |
double neighborUp = Math.nextUp(powerOfTwo); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
73 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
74 |
if (i < 0) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
75 |
failures += testCeilCase( powerOfTwo, 1.0); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
76 |
failures += testCeilCase(-powerOfTwo, -0.0); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
77 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
78 |
failures += testFloorCase( powerOfTwo, 0.0); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
79 |
failures += testFloorCase(-powerOfTwo, -1.0); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
80 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
81 |
failures += testCeilCase( neighborDown, 1.0); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
82 |
failures += testCeilCase(-neighborDown, -0.0); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
83 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
84 |
failures += testFloorCase( neighborUp, 0.0); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
85 |
failures += testFloorCase(-neighborUp, -1.0); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
86 |
} else { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
87 |
failures += testCeilCase(powerOfTwo, powerOfTwo); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
88 |
failures += testFloorCase(powerOfTwo, powerOfTwo); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
89 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
90 |
if (neighborDown==Math.rint(neighborDown)) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
91 |
failures += testCeilCase( neighborDown, neighborDown); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
92 |
failures += testCeilCase(-neighborDown, -neighborDown); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
93 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
94 |
failures += testFloorCase( neighborDown, neighborDown); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
95 |
failures += testFloorCase(-neighborDown,-neighborDown); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
96 |
} else { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
97 |
failures += testCeilCase( neighborDown, powerOfTwo); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
98 |
failures += testFloorCase(-neighborDown, -powerOfTwo); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
99 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
100 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
101 |
if (neighborUp==Math.rint(neighborUp)) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
102 |
failures += testCeilCase(neighborUp, neighborUp); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
103 |
failures += testCeilCase(-neighborUp, -neighborUp); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
104 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
105 |
failures += testFloorCase(neighborUp, neighborUp); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
106 |
failures += testFloorCase(-neighborUp, -neighborUp); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
107 |
} else { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
108 |
failures += testFloorCase(neighborUp, powerOfTwo); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
109 |
failures += testCeilCase(-neighborUp, -powerOfTwo); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
110 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
111 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
112 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
113 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
114 |
for(int i = -(0x10000); i <= 0x10000; i++) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
115 |
double d = (double) i; |
10608 | 116 |
double neighborDown = Math.nextDown(d); |
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
117 |
double neighborUp = Math.nextUp(d); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
118 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
119 |
failures += testCeilCase( d, d); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
120 |
failures += testCeilCase(-d, -d); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
121 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
122 |
failures += testFloorCase( d, d); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
123 |
failures += testFloorCase(-d, -d); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
124 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
125 |
if (Math.abs(d) > 1.0) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
126 |
failures += testCeilCase( neighborDown, d); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
127 |
failures += testCeilCase(-neighborDown, -d+1); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
128 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
129 |
failures += testFloorCase( neighborUp, d); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
130 |
failures += testFloorCase(-neighborUp, -d-1); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
131 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
132 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
133 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
134 |
return failures; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
135 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
136 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
137 |
public static int roundingTests() { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
138 |
int failures = 0; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
139 |
double [][] testCases = { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
140 |
{ Double.MIN_VALUE, 1.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
141 |
{-Double.MIN_VALUE, -0.0}, |
10608 | 142 |
{ Math.nextDown(DoubleConsts.MIN_NORMAL), 1.0}, |
143 |
{-Math.nextDown(DoubleConsts.MIN_NORMAL), -0.0}, |
|
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
144 |
{ DoubleConsts.MIN_NORMAL, 1.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
145 |
{-DoubleConsts.MIN_NORMAL, -0.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
146 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
147 |
{ 0.1, 1.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
148 |
{-0.1, -0.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
149 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
150 |
{ 0.5, 1.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
151 |
{-0.5, -0.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
152 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
153 |
{ 1.5, 2.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
154 |
{-1.5, -1.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
155 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
156 |
{ 2.5, 3.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
157 |
{-2.5, -2.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
158 |
|
10608 | 159 |
{ Math.nextDown(1.0), 1.0}, |
160 |
{ Math.nextDown(-1.0), -1.0}, |
|
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
161 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
162 |
{ Math.nextUp(1.0), 2.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
163 |
{ Math.nextUp(-1.0), -0.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
164 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
165 |
{ 0x1.0p51, 0x1.0p51}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
166 |
{-0x1.0p51, -0x1.0p51}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
167 |
|
10608 | 168 |
{ Math.nextDown(0x1.0p51), 0x1.0p51}, |
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
169 |
{-Math.nextUp(0x1.0p51), -0x1.0p51}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
170 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
171 |
{ Math.nextUp(0x1.0p51), 0x1.0p51+1}, |
10608 | 172 |
{-Math.nextDown(0x1.0p51), -0x1.0p51+1}, |
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
173 |
|
10608 | 174 |
{ Math.nextDown(0x1.0p52), 0x1.0p52}, |
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
175 |
{-Math.nextUp(0x1.0p52), -0x1.0p52-1.0}, |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
176 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
177 |
{ Math.nextUp(0x1.0p52), 0x1.0p52+1.0}, |
10608 | 178 |
{-Math.nextDown(0x1.0p52), -0x1.0p52+1.0}, |
4520
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
179 |
}; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
180 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
181 |
for(double[] testCase : testCases) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
182 |
failures += testCeilCase(testCase[0], testCase[1]); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
183 |
failures += testFloorCase(-testCase[0], -testCase[1]); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
184 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
185 |
return failures; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
186 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
187 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
188 |
public static void main(String... args) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
189 |
int failures = 0; |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
190 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
191 |
failures += nearIntegerTests(); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
192 |
failures += roundingTests(); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
193 |
|
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
194 |
if (failures > 0) { |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
195 |
System.err.println("Testing {Math, StrictMath}.ceil incurred " |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
196 |
+ failures + " failures."); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
197 |
throw new RuntimeException(); |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
198 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
199 |
} |
d2c9d06b5b31
6908131: Pure Java implementations of StrictMath.floor(double) & StrictMath.ceil(double)
darcy
parents:
diff
changeset
|
200 |
} |