1 /*
2 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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.
22 */
118 // e^x. Test two numbers before and two numbers after each
119 // chosen value; i.e.
120 //
121 // pcNeighbors[] =
122 // {nextDown(nextDown(pc)),
123 // nextDown(pc),
124 // pc,
125 // nextUp(pc),
126 // nextUp(nextUp(pc))}
127 //
128 // and we test that log1p(pcNeighbors[i]) <= log1p(pcNeighbors[i+1])
129 {
130 double pcNeighbors[] = new double[5];
131 double pcNeighborsLog1p[] = new double[5];
132 double pcNeighborsStrictLog1p[] = new double[5];
133
134 for(int i = -36; i <= 36; i++) {
135 double pc = StrictMath.pow(Math.E, i) - 1;
136
137 pcNeighbors[2] = pc;
138 pcNeighbors[1] = FpUtils.nextDown(pc);
139 pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
140 pcNeighbors[3] = Math.nextUp(pc);
141 pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
142
143 for(int j = 0; j < pcNeighbors.length; j++) {
144 pcNeighborsLog1p[j] = Math.log1p(pcNeighbors[j]);
145 pcNeighborsStrictLog1p[j] = StrictMath.log1p(pcNeighbors[j]);
146 }
147
148 for(int j = 0; j < pcNeighborsLog1p.length-1; j++) {
149 if(pcNeighborsLog1p[j] > pcNeighborsLog1p[j+1] ) {
150 failures++;
151 System.err.println("Monotonicity failure for Math.log1p on " +
152 pcNeighbors[j] + " and " +
153 pcNeighbors[j+1] + "\n\treturned " +
154 pcNeighborsLog1p[j] + " and " +
155 pcNeighborsLog1p[j+1] );
156 }
157
158 if(pcNeighborsStrictLog1p[j] > pcNeighborsStrictLog1p[j+1] ) {
159 failures++;
185 failures += Tests.testUlpDiff("Math.lop1p(double",
186 input, Math.log1p(input),
187 expected, ulps);
188 failures += Tests.testUlpDiff("StrictMath.log1p(double",
189 input, StrictMath.log1p(input),
190 expected, ulps);
191 return failures;
192 }
193
194 public static void main(String argv[]) {
195 int failures = 0;
196
197 failures += testLog1p();
198
199 if (failures > 0) {
200 System.err.println("Testing log1p incurred "
201 + failures + " failures.");
202 throw new RuntimeException();
203 }
204 }
205
206 }
|
1 /*
2 * Copyright (c) 2003, 2011 Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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.
22 */
118 // e^x. Test two numbers before and two numbers after each
119 // chosen value; i.e.
120 //
121 // pcNeighbors[] =
122 // {nextDown(nextDown(pc)),
123 // nextDown(pc),
124 // pc,
125 // nextUp(pc),
126 // nextUp(nextUp(pc))}
127 //
128 // and we test that log1p(pcNeighbors[i]) <= log1p(pcNeighbors[i+1])
129 {
130 double pcNeighbors[] = new double[5];
131 double pcNeighborsLog1p[] = new double[5];
132 double pcNeighborsStrictLog1p[] = new double[5];
133
134 for(int i = -36; i <= 36; i++) {
135 double pc = StrictMath.pow(Math.E, i) - 1;
136
137 pcNeighbors[2] = pc;
138 pcNeighbors[1] = Math.nextDown(pc);
139 pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
140 pcNeighbors[3] = Math.nextUp(pc);
141 pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
142
143 for(int j = 0; j < pcNeighbors.length; j++) {
144 pcNeighborsLog1p[j] = Math.log1p(pcNeighbors[j]);
145 pcNeighborsStrictLog1p[j] = StrictMath.log1p(pcNeighbors[j]);
146 }
147
148 for(int j = 0; j < pcNeighborsLog1p.length-1; j++) {
149 if(pcNeighborsLog1p[j] > pcNeighborsLog1p[j+1] ) {
150 failures++;
151 System.err.println("Monotonicity failure for Math.log1p on " +
152 pcNeighbors[j] + " and " +
153 pcNeighbors[j+1] + "\n\treturned " +
154 pcNeighborsLog1p[j] + " and " +
155 pcNeighborsLog1p[j+1] );
156 }
157
158 if(pcNeighborsStrictLog1p[j] > pcNeighborsStrictLog1p[j+1] ) {
159 failures++;
185 failures += Tests.testUlpDiff("Math.lop1p(double",
186 input, Math.log1p(input),
187 expected, ulps);
188 failures += Tests.testUlpDiff("StrictMath.log1p(double",
189 input, StrictMath.log1p(input),
190 expected, ulps);
191 return failures;
192 }
193
194 public static void main(String argv[]) {
195 int failures = 0;
196
197 failures += testLog1p();
198
199 if (failures > 0) {
200 System.err.println("Testing log1p incurred "
201 + failures + " failures.");
202 throw new RuntimeException();
203 }
204 }
205 }
|