1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package org.apache.harmony.luni.tests.java.lang;
19
20import static org.apache.harmony.luni.tests.java.lang.MathTest.COPYSIGN_DD_CASES;
21import static org.apache.harmony.luni.tests.java.lang.MathTest.COPYSIGN_FF_CASES;
22import static org.apache.harmony.luni.tests.java.lang.MathTest.GETEXPONENT_D_CASES;
23import static org.apache.harmony.luni.tests.java.lang.MathTest.GETEXPONENT_D_RESULTS;
24import static org.apache.harmony.luni.tests.java.lang.MathTest.GETEXPONENT_F_CASES;
25import static org.apache.harmony.luni.tests.java.lang.MathTest.GETEXPONENT_F_RESULTS;
26import static org.apache.harmony.luni.tests.java.lang.MathTest.NEXTAFTER_DD_START_CASES;
27import static org.apache.harmony.luni.tests.java.lang.MathTest.NEXTAFTER_DD_FD_DIRECTION_CASES;
28import static org.apache.harmony.luni.tests.java.lang.MathTest.NEXTAFTER_FD_START_CASES;
29
30public class StrictMathTest extends junit.framework.TestCase {
31
32	double HYP = StrictMath.sqrt(2.0);
33
34	double OPP = 1.0;
35
36	double ADJ = 1.0;
37
38	/* Required to make previous preprocessor flags work - do not remove */
39	int unused = 0;
40
41	/**
42	 * @tests java.lang.StrictMath#abs(double)
43	 */
44	public void test_absD() {
45		// Test for method double java.lang.StrictMath.abs(double)
46
47		assertTrue("Incorrect double abs value",
48				(StrictMath.abs(-1908.8976) == 1908.8976));
49		assertTrue("Incorrect double abs value",
50				(StrictMath.abs(1908.8976) == 1908.8976));
51	}
52
53	/**
54	 * @tests java.lang.StrictMath#abs(float)
55	 */
56	public void test_absF() {
57		// Test for method float java.lang.StrictMath.abs(float)
58		assertTrue("Incorrect float abs value",
59				(StrictMath.abs(-1908.8976f) == 1908.8976f));
60		assertTrue("Incorrect float abs value",
61				(StrictMath.abs(1908.8976f) == 1908.8976f));
62	}
63
64	/**
65	 * @tests java.lang.StrictMath#abs(int)
66	 */
67	public void test_absI() {
68		// Test for method int java.lang.StrictMath.abs(int)
69		assertTrue("Incorrect int abs value",
70				(StrictMath.abs(-1908897) == 1908897));
71		assertTrue("Incorrect int abs value",
72				(StrictMath.abs(1908897) == 1908897));
73	}
74
75	/**
76	 * @tests java.lang.StrictMath#abs(long)
77	 */
78	public void test_absJ() {
79		// Test for method long java.lang.StrictMath.abs(long)
80		assertTrue("Incorrect long abs value", (StrictMath
81				.abs(-19088976000089L) == 19088976000089L));
82		assertTrue("Incorrect long abs value",
83				(StrictMath.abs(19088976000089L) == 19088976000089L));
84	}
85
86	/**
87	 * @tests java.lang.StrictMath#acos(double)
88	 */
89	public void test_acosD() {
90		// Test for method double java.lang.StrictMath.acos(double)
91		assertTrue("Returned incorrect arc cosine", StrictMath.cos(StrictMath
92				.acos(ADJ / HYP)) == ADJ / HYP);
93	}
94
95	/**
96	 * @tests java.lang.StrictMath#asin(double)
97	 */
98	public void test_asinD() {
99		// Test for method double java.lang.StrictMath.asin(double)
100		assertTrue("Returned incorrect arc sine", StrictMath.sin(StrictMath
101				.asin(OPP / HYP)) == OPP / HYP);
102	}
103
104	/**
105	 * @tests java.lang.StrictMath#atan(double)
106	 */
107	public void test_atanD() {
108		// Test for method double java.lang.StrictMath.atan(double)
109		double answer = StrictMath.tan(StrictMath.atan(1.0));
110		assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
111				&& answer >= 9.9999999999999983E-1);
112	}
113
114	/**
115	 * @tests java.lang.StrictMath#atan2(double, double)
116	 */
117	public void test_atan2DD() {
118		// Test for method double java.lang.StrictMath.atan2(double, double)
119		double answer = StrictMath.atan(StrictMath.tan(1.0));
120		assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
121				&& answer >= 9.9999999999999983E-1);
122	}
123
124    /**
125     * @tests java.lang.StrictMath#cbrt(double)
126     */
127    @SuppressWarnings("boxing")
128    public void test_cbrt_D() {
129        // Test for special situations
130        assertTrue("Should return Double.NaN", Double.isNaN(StrictMath
131                .cbrt(Double.NaN)));
132        assertEquals("Should return Double.POSITIVE_INFINITY",
133                Double.POSITIVE_INFINITY, StrictMath
134                        .cbrt(Double.POSITIVE_INFINITY));
135        assertEquals("Should return Double.NEGATIVE_INFINITY",
136                Double.NEGATIVE_INFINITY, StrictMath
137                        .cbrt(Double.NEGATIVE_INFINITY));
138        assertEquals(Double.doubleToLongBits(0.0), Double
139				.doubleToLongBits(StrictMath.cbrt(0.0)));
140		assertEquals(Double.doubleToLongBits(+0.0), Double
141				.doubleToLongBits(StrictMath.cbrt(+0.0)));
142		assertEquals(Double.doubleToLongBits(-0.0), Double
143				.doubleToLongBits(StrictMath.cbrt(-0.0)));
144
145        assertEquals("Should return 3.0", 3.0, StrictMath.cbrt(27.0));
146        assertEquals("Should return 23.111993172558684", 23.111993172558684,
147                StrictMath.cbrt(12345.6));
148        assertEquals("Should return 5.643803094122362E102",
149                5.643803094122362E102, StrictMath.cbrt(Double.MAX_VALUE));
150        assertEquals("Should return 0.01", 0.01, StrictMath.cbrt(0.000001));
151
152        assertEquals("Should return -3.0", -3.0, StrictMath.cbrt(-27.0));
153        assertEquals("Should return -23.111993172558684", -23.111993172558684,
154                StrictMath.cbrt(-12345.6));
155        assertEquals("Should return 1.7031839360032603E-108",
156                1.7031839360032603E-108, StrictMath.cbrt(Double.MIN_VALUE));
157        assertEquals("Should return -0.01", -0.01, StrictMath.cbrt(-0.000001));
158
159        try{
160            StrictMath.cbrt((Double)null);
161            fail("Should throw NullPointerException");
162        }catch(NullPointerException e){
163            //expected
164        }
165    }
166
167	/**
168	 * @tests java.lang.StrictMath#ceil(double)
169	 */
170	public void test_ceilD() {
171		// Test for method double java.lang.StrictMath.ceil(double)
172                assertEquals("Incorrect ceiling for double",
173                             79, StrictMath.ceil(78.89), 0.0);
174		assertEquals("Incorrect ceiling for double",
175                             -78, StrictMath.ceil(-78.89), 0.0);
176	}
177
178	/**
179     * @tests {@link java.lang.StrictMath#copySign(double, double)}
180     * @since 1.6
181     */
182    @SuppressWarnings("boxing")
183    public void test_copySign_DD() {
184        for (int i = 0; i < COPYSIGN_DD_CASES.length; i++) {
185            final double magnitude = COPYSIGN_DD_CASES[i];
186            final long absMagnitudeBits = Double.doubleToLongBits(StrictMath
187                    .abs(magnitude));
188            final long negMagnitudeBits = Double.doubleToLongBits(-StrictMath
189                    .abs(magnitude));
190
191            // cases for NaN
192            assertEquals("If the sign is NaN, the result should be positive.",
193                    absMagnitudeBits, Double.doubleToLongBits(StrictMath
194                            .copySign(magnitude, Double.NaN)));
195            assertTrue("The result should be NaN.", Double.isNaN(StrictMath
196                    .copySign(Double.NaN, magnitude)));
197
198            for (int j = 0; j < COPYSIGN_DD_CASES.length; j++) {
199                final double sign = COPYSIGN_DD_CASES[j];
200                final long resultBits = Double.doubleToLongBits(StrictMath
201                        .copySign(magnitude, sign));
202
203                if (sign > 0 || Double.valueOf(+0.0).equals(sign)
204                        || Double.valueOf(0.0).equals(sign)) {
205                    assertEquals(
206                            "If the sign is positive, the result should be positive.",
207                            absMagnitudeBits, resultBits);
208                }
209                if (sign < 0 || Double.valueOf(-0.0).equals(sign)) {
210                    assertEquals(
211                            "If the sign is negative, the result should be negative.",
212                            negMagnitudeBits, resultBits);
213                }
214            }
215        }
216
217        assertTrue("The result should be NaN.", Double.isNaN(StrictMath
218                .copySign(Double.NaN, Double.NaN)));
219
220        try {
221            StrictMath.copySign((Double) null, 2.3);
222            fail("Should throw NullPointerException");
223        } catch (NullPointerException e) {
224            // Expected
225        }
226        try {
227            StrictMath.copySign(2.3, (Double) null);
228            fail("Should throw NullPointerException");
229        } catch (NullPointerException e) {
230            // Expected
231        }
232        try {
233            StrictMath.copySign((Double) null, (Double) null);
234            fail("Should throw NullPointerException");
235        } catch (NullPointerException e) {
236            // Expected
237        }
238
239		double d = Double.longBitsToDouble(0xfff8000000000000L);
240		assertEquals(1.0, StrictMath.copySign(1.0, d), 0d);
241    }
242
243    /**
244     * @tests {@link java.lang.StrictMath#copySign(float, float)}
245     * @since 1.6
246     */
247    @SuppressWarnings("boxing")
248    public void test_copySign_FF() {
249        for (int i = 0; i < COPYSIGN_FF_CASES.length; i++) {
250            final float magnitude = COPYSIGN_FF_CASES[i];
251            final int absMagnitudeBits = Float.floatToIntBits(StrictMath
252                    .abs(magnitude));
253            final int negMagnitudeBits = Float.floatToIntBits(-StrictMath
254                    .abs(magnitude));
255
256            // cases for NaN
257            assertEquals("If the sign is NaN, the result should be positive.",
258                    absMagnitudeBits, Float.floatToIntBits(StrictMath.copySign(
259                            magnitude, Float.NaN)));
260            assertTrue("The result should be NaN.", Float.isNaN(StrictMath
261                    .copySign(Float.NaN, magnitude)));
262
263            for (int j = 0; j < COPYSIGN_FF_CASES.length; j++) {
264                final float sign = COPYSIGN_FF_CASES[j];
265                final int resultBits = Float.floatToIntBits(StrictMath
266                        .copySign(magnitude, sign));
267                if (sign > 0 || Float.valueOf(+0.0f).equals(sign)
268                        || Float.valueOf(0.0f).equals(sign)) {
269                    assertEquals(
270                            "If the sign is positive, the result should be positive.",
271                            absMagnitudeBits, resultBits);
272                }
273                if (sign < 0 || Float.valueOf(-0.0f).equals(sign)) {
274                    assertEquals(
275                            "If the sign is negative, the result should be negative.",
276                            negMagnitudeBits, resultBits);
277                }
278            }
279        }
280
281        assertTrue("The result should be NaN.", Float.isNaN(StrictMath
282                .copySign(Float.NaN, Float.NaN)));
283
284        try {
285            StrictMath.copySign((Float) null, 2.3f);
286            fail("Should throw NullPointerException");
287        } catch (NullPointerException e) {
288            // Expected
289        }
290        try {
291            StrictMath.copySign(2.3f, (Float) null);
292            fail("Should throw NullPointerException");
293        } catch (NullPointerException e) {
294            // Expected
295        }
296        try {
297            StrictMath.copySign((Float) null, (Float) null);
298            fail("Should throw NullPointerException");
299        } catch (NullPointerException e) {
300            // Expected
301        }
302
303		float f = Float.intBitsToFloat(0xffc00000);
304		assertEquals(1.0f, StrictMath.copySign(1.0f, f), 0f);
305    }
306
307	/**
308	 * @tests java.lang.StrictMath#cos(double)
309	 */
310	public void test_cosD() {
311		// Test for method double java.lang.StrictMath.cos(double)
312
313		assertTrue("Returned incorrect cosine", StrictMath.cos(StrictMath
314				.acos(ADJ / HYP)) == ADJ / HYP);
315	}
316
317    /**
318     * @tests java.lang.StrictMath#cosh(double)
319     */
320    @SuppressWarnings("boxing")
321    public void test_cosh_D() {
322        // Test for special situations
323        assertTrue("Should return NaN", Double.isNaN(StrictMath
324                .cosh(Double.NaN)));
325        assertEquals("Should return POSITIVE_INFINITY",
326                Double.POSITIVE_INFINITY, StrictMath
327                        .cosh(Double.POSITIVE_INFINITY));
328        assertEquals("Should return POSITIVE_INFINITY",
329                Double.POSITIVE_INFINITY, StrictMath
330                        .cosh(Double.NEGATIVE_INFINITY));
331        assertEquals("Should return 1.0", 1.0, StrictMath.cosh(+0.0));
332        assertEquals("Should return 1.0", 1.0, StrictMath.cosh(-0.0));
333
334        assertEquals("Should return POSITIVE_INFINITY",
335                Double.POSITIVE_INFINITY, StrictMath.cosh(1234.56));
336        assertEquals("Should return POSITIVE_INFINITY",
337                Double.POSITIVE_INFINITY, StrictMath.cosh(-1234.56));
338        assertEquals("Should return 1.0000000000005", 1.0000000000005,
339                StrictMath.cosh(0.000001));
340        assertEquals("Should return 1.0000000000005", 1.0000000000005,
341                StrictMath.cosh(-0.000001));
342        assertEquals("Should return 5.212214351945598", 5.212214351945598,
343                StrictMath.cosh(2.33482));
344
345        assertEquals("Should return POSITIVE_INFINITY",
346                Double.POSITIVE_INFINITY, StrictMath.cosh(Double.MAX_VALUE));
347        assertEquals("Should return 1.0", 1.0, StrictMath
348                .cosh(Double.MIN_VALUE));
349    }
350
351	/**
352	 * @tests java.lang.StrictMath#exp(double)
353	 */
354	public void test_expD() {
355		// Test for method double java.lang.StrictMath.exp(double)
356		assertTrue("Incorrect answer returned for simple power", StrictMath
357				.abs(StrictMath.exp(4D) - StrictMath.E * StrictMath.E
358						* StrictMath.E * StrictMath.E) < 0.1D);
359		assertTrue("Incorrect answer returned for larger power", StrictMath
360				.log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D);
361	}
362
363    /**
364     * @tests java.lang.StrictMath#expm1(double)
365     */
366    @SuppressWarnings("boxing")
367    public void test_expm1_D() {
368        //Test for special cases
369        assertTrue("Should return NaN", Double.isNaN(StrictMath.expm1(Double.NaN)));
370        assertEquals("Should return POSITIVE_INFINITY",
371                Double.POSITIVE_INFINITY, StrictMath.expm1(Double.POSITIVE_INFINITY));
372        assertEquals("Should return -1.0", -1.0, StrictMath
373                .expm1(Double.NEGATIVE_INFINITY));
374        assertEquals(Double.doubleToLongBits(0.0), Double
375				.doubleToLongBits(StrictMath.expm1(0.0)));
376		assertEquals(Double.doubleToLongBits(+0.0), Double
377				.doubleToLongBits(StrictMath.expm1(+0.0)));
378		assertEquals(Double.doubleToLongBits(-0.0), Double
379				.doubleToLongBits(StrictMath.expm1(-0.0)));
380
381        assertEquals("Should return -9.999950000166666E-6",
382                -9.999950000166666E-6, StrictMath.expm1(-0.00001));
383        assertEquals("Should return 1.0145103074469635E60",
384                1.0145103074469635E60, StrictMath.expm1(138.16951162));
385        assertEquals("Should return POSITIVE_INFINITY",
386                Double.POSITIVE_INFINITY, StrictMath
387                        .expm1(123456789123456789123456789.4521584223));
388        assertEquals("Should return POSITIVE_INFINITY",
389                Double.POSITIVE_INFINITY, StrictMath.expm1(Double.MAX_VALUE));
390        assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, StrictMath
391                .expm1(Double.MIN_VALUE));
392
393    }
394
395	/**
396	 * @tests java.lang.StrictMath#floor(double)
397	 */
398	public void test_floorD() {
399		// Test for method double java.lang.StrictMath.floor(double)
400                assertEquals("Incorrect floor for double",
401                             78, StrictMath.floor(78.89), 0.0);
402		assertEquals("Incorrect floor for double",
403                             -79, StrictMath.floor(-78.89), 0.0);
404	}
405
406	/**
407     * @tests {@link java.lang.StrictMath#getExponent(double)}
408     * @since 1.6
409     */
410    @SuppressWarnings("boxing")
411    public void test_getExponent_D() {
412        for (int i = 0; i < GETEXPONENT_D_CASES.length; i++) {
413            final double number = GETEXPONENT_D_CASES[i];
414            final int result = GETEXPONENT_D_RESULTS[i];
415            assertEquals("Wrong result of getExponent(double).", result,
416                    StrictMath.getExponent(number));
417        }
418
419        try {
420            StrictMath.getExponent((Double) null);
421            fail("Should throw NullPointerException");
422        } catch (NullPointerException e) {
423            // Expected
424        }
425    }
426
427    /**
428     * @tests {@link java.lang.StrictMath#getExponent(float)}
429     * @since 1.6
430     */
431    @SuppressWarnings("boxing")
432    public void test_getExponent_F() {
433        for (int i = 0; i < GETEXPONENT_F_CASES.length; i++) {
434            final float number = GETEXPONENT_F_CASES[i];
435            final int result = GETEXPONENT_F_RESULTS[i];
436            assertEquals("Wrong result of getExponent(float).", result,
437                    StrictMath.getExponent(number));
438        }
439        try {
440            StrictMath.getExponent((Float) null);
441            fail("Should throw NullPointerException");
442        } catch (NullPointerException e) {
443            // Expected
444        }
445    }
446
447    /**
448     * @tests java.lang.StrictMath#hypot(double, double)
449     */
450    @SuppressWarnings("boxing")
451    public void test_hypot_DD() {
452        // Test for special cases
453        assertEquals("Should return POSITIVE_INFINITY",
454                Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY,
455                        1.0));
456        assertEquals("Should return POSITIVE_INFINITY",
457                Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
458                        123.324));
459        assertEquals("Should return POSITIVE_INFINITY",
460                Double.POSITIVE_INFINITY, StrictMath.hypot(-758.2587,
461                        Double.POSITIVE_INFINITY));
462        assertEquals("Should return POSITIVE_INFINITY",
463                Double.POSITIVE_INFINITY, StrictMath.hypot(5687.21,
464                        Double.NEGATIVE_INFINITY));
465        assertEquals("Should return POSITIVE_INFINITY",
466                Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY,
467                        Double.NEGATIVE_INFINITY));
468        assertEquals("Should return POSITIVE_INFINITY",
469                Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
470                        Double.POSITIVE_INFINITY));
471        assertTrue("Should return NaN",Double.isNaN(StrictMath.hypot(Double.NaN,
472                2342301.89843)));
473        assertTrue("Should return NaN",Double.isNaN(StrictMath.hypot(-345.2680,
474                Double.NaN)));
475
476        assertEquals("Should return 2396424.905416697", 2396424.905416697, StrictMath
477                .hypot(12322.12, -2396393.2258));
478        assertEquals("Should return 138.16958070558556", 138.16958070558556,
479                StrictMath.hypot(-138.16951162, 0.13817035864));
480        assertEquals("Should return 1.7976931348623157E308",
481                1.7976931348623157E308, StrictMath.hypot(Double.MAX_VALUE, 211370.35));
482        assertEquals("Should return 5413.7185", 5413.7185, StrictMath.hypot(
483                -5413.7185, Double.MIN_VALUE));
484
485    }
486
487	/**
488	 * @tests java.lang.StrictMath#IEEEremainder(double, double)
489	 */
490	public void test_IEEEremainderDD() {
491		// Test for method double java.lang.StrictMath.IEEEremainder(double,
492		// double)
493		assertEquals("Incorrect remainder returned", 0.0, StrictMath.IEEEremainder(
494				1.0, 1.0), 0.0);
495		assertTrue(
496				"Incorrect remainder returned",
497				StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2
498						|| StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
499	}
500
501	/**
502	 * @tests java.lang.StrictMath#log(double)
503	 */
504	public void test_logD() {
505		// Test for method double java.lang.StrictMath.log(double)
506		for (double d = 10; d >= -10; d -= 0.5) {
507			double answer = StrictMath.log(StrictMath.exp(d));
508			assertTrue("Answer does not equal expected answer for d = " + d
509					+ " answer = " + answer,
510					StrictMath.abs(answer - d) <= StrictMath
511							.abs(d * 0.00000001));
512		}
513	}
514
515    /**
516     * @tests java.lang.StrictMath#log10(double)
517     */
518    @SuppressWarnings("boxing")
519    public void test_log10_D() {
520        // Test for special cases
521        assertTrue("Should return NaN", Double.isNaN(StrictMath
522                .log10(Double.NaN)));
523        assertTrue("Should return NaN", Double.isNaN(StrictMath
524                .log10(-2541.05745687234187532)));
525        assertEquals("Should return POSITIVE_INFINITY",
526                Double.POSITIVE_INFINITY, StrictMath
527                        .log10(Double.POSITIVE_INFINITY));
528        assertEquals("Should return NEGATIVE_INFINITY",
529                Double.NEGATIVE_INFINITY, StrictMath.log10(0.0));
530        assertEquals("Should return NEGATIVE_INFINITY",
531                Double.NEGATIVE_INFINITY, StrictMath.log10(+0.0));
532        assertEquals("Should return NEGATIVE_INFINITY",
533                Double.NEGATIVE_INFINITY, StrictMath.log10(-0.0));
534        assertEquals("Should return 14.0", 14.0, StrictMath.log10(StrictMath
535                .pow(10, 14)));
536
537        assertEquals("Should return 3.7389561269540406", 3.7389561269540406,
538                StrictMath.log10(5482.2158));
539        assertEquals("Should return 14.661551142893833", 14.661551142893833,
540                StrictMath.log10(458723662312872.125782332587));
541        assertEquals("Should return -0.9083828622192334", -0.9083828622192334,
542                StrictMath.log10(0.12348583358871));
543        assertEquals("Should return 308.25471555991675", 308.25471555991675,
544                StrictMath.log10(Double.MAX_VALUE));
545        assertEquals("Should return -323.3062153431158", -323.3062153431158,
546                StrictMath.log10(Double.MIN_VALUE));
547    }
548
549    /**
550     * @tests java.lang.StrictMath#log1p(double)
551     */
552    @SuppressWarnings("boxing")
553    public void test_log1p_D() {
554        // Test for special cases
555        assertTrue("Should return NaN", Double.isNaN(StrictMath
556                .log1p(Double.NaN)));
557        assertTrue("Should return NaN", Double.isNaN(StrictMath
558                .log1p(-32.0482175)));
559        assertEquals("Should return POSITIVE_INFINITY",
560                Double.POSITIVE_INFINITY, StrictMath
561                        .log1p(Double.POSITIVE_INFINITY));
562        assertEquals(Double.doubleToLongBits(0.0), Double
563				.doubleToLongBits(StrictMath.log1p(0.0)));
564		assertEquals(Double.doubleToLongBits(+0.0), Double
565				.doubleToLongBits(StrictMath.log1p(+0.0)));
566		assertEquals(Double.doubleToLongBits(-0.0), Double
567				.doubleToLongBits(StrictMath.log1p(-0.0)));
568
569        assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
570                StrictMath.log1p(-0.254856327));
571        assertEquals("Should return 7.368050685564151", 7.368050685564151,
572                StrictMath.log1p(1583.542));
573        assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
574                StrictMath.log1p(0.5894227));
575        assertEquals("Should return 709.782712893384", 709.782712893384,
576                StrictMath.log1p(Double.MAX_VALUE));
577        assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE,
578                StrictMath.log1p(Double.MIN_VALUE));
579    }
580
581    /**
582     * @tests java.lang.StrictMath#max(double, double)
583     */
584	public void test_maxDD() {
585		// Test for method double java.lang.StrictMath.max(double, double)
586		assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(
587				-1908897.6000089, 1908897.6000089), 0D);
588		assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(2.0,
589				1908897.6000089), 0D);
590		assertEquals("Incorrect double max value", -2.0, StrictMath.max(-2.0,
591				-1908897.6000089), 0D);
592
593	}
594
595	/**
596	 * @tests java.lang.StrictMath#max(float, float)
597	 */
598	public void test_maxFF() {
599		// Test for method float java.lang.StrictMath.max(float, float)
600		assertTrue("Incorrect float max value", StrictMath.max(-1908897.600f,
601				1908897.600f) == 1908897.600f);
602		assertTrue("Incorrect float max value", StrictMath.max(2.0f,
603				1908897.600f) == 1908897.600f);
604		assertTrue("Incorrect float max value", StrictMath.max(-2.0f,
605				-1908897.600f) == -2.0f);
606	}
607
608	/**
609	 * @tests java.lang.StrictMath#max(int, int)
610	 */
611	public void test_maxII() {
612		// Test for method int java.lang.StrictMath.max(int, int)
613		assertEquals("Incorrect int max value", 19088976, StrictMath.max(-19088976,
614				19088976));
615		assertEquals("Incorrect int max value",
616				19088976, StrictMath.max(20, 19088976));
617		assertEquals("Incorrect int max value",
618				-20, StrictMath.max(-20, -19088976));
619	}
620
621	/**
622	 * @tests java.lang.StrictMath#max(long, long)
623	 */
624	public void test_maxJJ() {
625		// Test for method long java.lang.StrictMath.max(long, long)
626		assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(-19088976000089L,
627				19088976000089L));
628		assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(20,
629				19088976000089L));
630		assertEquals("Incorrect long max value", -20, StrictMath.max(-20,
631				-19088976000089L));
632	}
633
634	/**
635	 * @tests java.lang.StrictMath#min(double, double)
636	 */
637	public void test_minDD() {
638		// Test for method double java.lang.StrictMath.min(double, double)
639		assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(
640				-1908897.6000089, 1908897.6000089), 0D);
641		assertEquals("Incorrect double min value", 2.0, StrictMath.min(2.0,
642				1908897.6000089), 0D);
643		assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(-2.0,
644				-1908897.6000089), 0D);
645	}
646
647	/**
648	 * @tests java.lang.StrictMath#min(float, float)
649	 */
650	public void test_minFF() {
651		// Test for method float java.lang.StrictMath.min(float, float)
652		assertTrue("Incorrect float min value", StrictMath.min(-1908897.600f,
653				1908897.600f) == -1908897.600f);
654		assertTrue("Incorrect float min value", StrictMath.min(2.0f,
655				1908897.600f) == 2.0f);
656		assertTrue("Incorrect float min value", StrictMath.min(-2.0f,
657				-1908897.600f) == -1908897.600f);
658	}
659
660	/**
661	 * @tests java.lang.StrictMath#min(int, int)
662	 */
663	public void test_minII() {
664		// Test for method int java.lang.StrictMath.min(int, int)
665		assertEquals("Incorrect int min value", -19088976, StrictMath.min(-19088976,
666				19088976));
667		assertEquals("Incorrect int min value",
668				20, StrictMath.min(20, 19088976));
669		assertEquals("Incorrect int min value",
670				-19088976, StrictMath.min(-20, -19088976));
671
672	}
673
674	/**
675	 * @tests java.lang.StrictMath#min(long, long)
676	 */
677	public void test_minJJ() {
678		// Test for method long java.lang.StrictMath.min(long, long)
679		assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-19088976000089L,
680				19088976000089L));
681		assertEquals("Incorrect long min value", 20, StrictMath.min(20,
682				19088976000089L));
683		assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-20,
684				-19088976000089L));
685	}
686
687	 /**
688     * @tests {@link java.lang.StrictMath#nextAfter(double, double)}
689     * @since 1.6
690     */
691    @SuppressWarnings("boxing")
692    public void test_nextAfter_DD() {
693        // test for most cases without exception
694        for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
695            final double start = NEXTAFTER_DD_START_CASES[i][0];
696            final long nextUpBits = Double
697                    .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]);
698            final long nextDownBits = Double
699                    .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][2]);
700
701            for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) {
702                final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j];
703                final long resultBits = Double.doubleToLongBits(StrictMath
704                        .nextAfter(start, direction));
705                final long directionBits = Double.doubleToLongBits(direction);
706                if (direction > start) {
707                    assertEquals("Result should be next up-number.",
708                            nextUpBits, resultBits);
709                } else if (direction < start) {
710                    assertEquals("Result should be next down-number.",
711                            nextDownBits, resultBits);
712                } else {
713                    assertEquals("Result should be direction.", directionBits,
714                            resultBits);
715                }
716            }
717        }
718
719        // test for cases with NaN
720        for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
721            assertTrue("The result should be NaN.", Double.isNaN(StrictMath
722                    .nextAfter(NEXTAFTER_DD_START_CASES[i][0], Double.NaN)));
723        }
724        for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) {
725            assertTrue("The result should be NaN.", Double.isNaN(StrictMath
726                    .nextAfter(Double.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i])));
727        }
728        assertTrue("The result should be NaN.", Double.isNaN(StrictMath
729                .nextAfter(Double.NaN, Double.NaN)));
730
731        // test for exception
732        try {
733            StrictMath.nextAfter((Double) null, 2.3);
734            fail("Should throw NullPointerException");
735        } catch (NullPointerException e) {
736            // Expected
737        }
738        try {
739            StrictMath.nextAfter(2.3, (Double) null);
740            fail("Should throw NullPointerException");
741        } catch (NullPointerException e) {
742            // Expected
743        }
744        try {
745            StrictMath.nextAfter((Double) null, (Double) null);
746            fail("Should throw NullPointerException");
747        } catch (NullPointerException e) {
748            // Expected
749        }
750    }
751
752    /**
753     * @tests {@link java.lang.StrictMath#nextAfter(float, double)}
754     * @since 1.6
755     */
756    @SuppressWarnings("boxing")
757    public void test_nextAfter_FD() {
758        // test for most cases without exception
759        for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
760            final float start = NEXTAFTER_FD_START_CASES[i][0];
761            final int nextUpBits = Float
762                    .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]);
763            final int nextDownBits = Float
764                    .floatToIntBits(NEXTAFTER_FD_START_CASES[i][2]);
765
766            for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) {
767                final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j];
768                final int resultBits = Float.floatToIntBits(StrictMath
769                        .nextAfter(start, direction));
770                if (direction > start) {
771                    assertEquals("Result should be next up-number.",
772                            nextUpBits, resultBits);
773                } else if (direction < start) {
774                    assertEquals("Result should be next down-number.",
775                            nextDownBits, resultBits);
776                } else {
777                    final int equivalentBits = Float.floatToIntBits(new Float(
778                            direction));
779                    assertEquals(
780                            "Result should be a number equivalent to direction.",
781                            equivalentBits, resultBits);
782                }
783            }
784        }
785
786        // test for cases with NaN
787        for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
788            assertTrue("The result should be NaN.", Float.isNaN(StrictMath
789                    .nextAfter(NEXTAFTER_FD_START_CASES[i][0], Float.NaN)));
790        }
791        for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) {
792            assertTrue("The result should be NaN.", Float.isNaN(StrictMath
793                    .nextAfter(Float.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i])));
794        }
795        assertTrue("The result should be NaN.", Float.isNaN(StrictMath
796                .nextAfter(Float.NaN, Float.NaN)));
797
798        // test for exception
799        try {
800            StrictMath.nextAfter((Float) null, 2.3);
801            fail("Should throw NullPointerException");
802        } catch (NullPointerException e) {
803            // Expected
804        }
805        try {
806            StrictMath.nextAfter(2.3, (Float) null);
807            fail("Should throw NullPointerException");
808        } catch (NullPointerException e) {
809            // Expected
810        }
811        try {
812            StrictMath.nextAfter((Float) null, (Float) null);
813            fail("Should throw NullPointerException");
814        } catch (NullPointerException e) {
815            // Expected
816        }
817    }
818
819    /**
820     * @tests {@link java.lang.StrictMath#nextUp(double)}
821     * @since 1.6
822     */
823    @SuppressWarnings("boxing")
824    public void test_nextUp_D() {
825        // This method is semantically equivalent to nextAfter(d,
826        // Double.POSITIVE_INFINITY),
827        // so we use the data of test_nextAfter_DD
828        for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
829            final double start = NEXTAFTER_DD_START_CASES[i][0];
830            final long nextUpBits = Double
831                    .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]);
832            final long resultBits = Double.doubleToLongBits(StrictMath
833                    .nextUp(start));
834            assertEquals("Result should be next up-number.", nextUpBits,
835                    resultBits);
836        }
837
838        // test for cases with NaN
839        assertTrue("The result should be NaN.", Double.isNaN(StrictMath
840                .nextUp(Double.NaN)));
841
842        // test for exception
843        try {
844            StrictMath.nextUp((Double) null);
845            fail("Should throw NullPointerException");
846        } catch (NullPointerException e) {
847            // Expected
848        }
849    }
850
851    /**
852     * @tests {@link java.lang.StrictMath#nextUp(float)}
853     * @since 1.6
854     */
855    @SuppressWarnings("boxing")
856    public void test_nextUp_F() {
857        // This method is semantically equivalent to nextAfter(f,
858        // Float.POSITIVE_INFINITY),
859        // so we use the data of test_nextAfter_FD
860        for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
861            final float start = NEXTAFTER_FD_START_CASES[i][0];
862            final int nextUpBits = Float
863                    .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]);
864            final int resultBits = Float.floatToIntBits(StrictMath
865                    .nextUp(start));
866            assertEquals("Result should be next up-number.", nextUpBits,
867                    resultBits);
868        }
869
870        // test for cases with NaN
871        assertTrue("The result should be NaN.", Float.isNaN(StrictMath
872                .nextUp(Float.NaN)));
873
874        // test for exception
875        try {
876            StrictMath.nextUp((Float) null);
877            fail("Should throw NullPointerException");
878        } catch (NullPointerException e) {
879            // Expected
880        }
881    }
882
883	/**
884	 * @tests java.lang.StrictMath#pow(double, double)
885	 */
886	public void test_powDD() {
887		// Test for method double java.lang.StrictMath.pow(double, double)
888		assertTrue("pow returned incorrect value",
889				(long) StrictMath.pow(2, 8) == 256l);
890		assertTrue("pow returned incorrect value",
891				StrictMath.pow(2, -8) == 0.00390625d);
892	}
893
894	/**
895	 * @tests java.lang.StrictMath#rint(double)
896	 */
897	public void test_rintD() {
898		// Test for method double java.lang.StrictMath.rint(double)
899		assertEquals("Failed to round properly - up to odd",
900				3.0, StrictMath.rint(2.9), 0D);
901		assertTrue("Failed to round properly - NaN", Double.isNaN(StrictMath
902				.rint(Double.NaN)));
903		assertEquals("Failed to round properly down  to even", 2.0, StrictMath
904				.rint(2.1), 0D);
905		assertTrue("Failed to round properly " + 2.5 + " to even", StrictMath
906				.rint(2.5) == 2.0);
907	}
908
909	/**
910	 * @tests java.lang.StrictMath#round(double)
911	 */
912	public void test_roundD() {
913		// Test for method long java.lang.StrictMath.round(double)
914		assertEquals("Incorrect rounding of a float",
915				-91, StrictMath.round(-90.89d));
916	}
917
918	/**
919	 * @tests java.lang.StrictMath#round(float)
920	 */
921	public void test_roundF() {
922		// Test for method int java.lang.StrictMath.round(float)
923		assertEquals("Incorrect rounding of a float",
924				-91, StrictMath.round(-90.89f));
925	}
926
927	/**
928     * @tests {@link java.lang.StrictMath#scalb(double, int)}
929     * @since 1.6
930     */
931    @SuppressWarnings("boxing")
932    public void test_scalb_DI() {
933        // result is normal
934        assertEquals(4.1422946304E7, StrictMath.scalb(1.2345, 25));
935        assertEquals(3.679096698760986E-8, StrictMath.scalb(1.2345, -25));
936        assertEquals(1.2345, StrictMath.scalb(1.2345, 0));
937        assertEquals(7868514.304, StrictMath.scalb(0.2345, 25));
938
939        double normal = StrictMath.scalb(0.2345, -25);
940        assertEquals(6.98864459991455E-9, normal);
941        // precision kept
942        assertEquals(0.2345, StrictMath.scalb(normal, 25));
943
944        assertEquals(0.2345, StrictMath.scalb(0.2345, 0));
945        assertEquals(-4.1422946304E7, StrictMath.scalb(-1.2345, 25));
946        assertEquals(-6.98864459991455E-9, StrictMath.scalb(-0.2345, -25));
947        assertEquals(2.0, StrictMath.scalb(Double.MIN_NORMAL / 2, 1024));
948        assertEquals(64.0, StrictMath.scalb(Double.MIN_VALUE, 1080));
949        assertEquals(234, StrictMath.getExponent(StrictMath.scalb(1.0, 234)));
950        assertEquals(3.9999999999999996, StrictMath.scalb(Double.MAX_VALUE,
951                Double.MIN_EXPONENT));
952
953        // result is near infinity
954        double halfMax = StrictMath.scalb(1.0, Double.MAX_EXPONENT);
955        assertEquals(8.98846567431158E307, halfMax);
956        assertEquals(Double.MAX_VALUE, halfMax - StrictMath.ulp(halfMax)
957                + halfMax);
958        assertEquals(Double.POSITIVE_INFINITY, halfMax + halfMax);
959        assertEquals(1.7976931348623155E308, StrictMath.scalb(1.0 - StrictMath
960                .ulp(1.0), Double.MAX_EXPONENT + 1));
961        assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
962                1.0 - StrictMath.ulp(1.0), Double.MAX_EXPONENT + 2));
963
964        halfMax = StrictMath.scalb(-1.0, Double.MAX_EXPONENT);
965        assertEquals(-8.98846567431158E307, halfMax);
966        assertEquals(-Double.MAX_VALUE, halfMax + StrictMath.ulp(halfMax)
967                + halfMax);
968        assertEquals(Double.NEGATIVE_INFINITY, halfMax + halfMax);
969
970        assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(0.345, 1234));
971        assertEquals(Double.POSITIVE_INFINITY, StrictMath
972                .scalb(44.345E102, 934));
973        assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb(-44.345E102,
974                934));
975
976        assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
977                Double.MIN_NORMAL / 2, 4000));
978        assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
979                Double.MIN_VALUE, 8000));
980        assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
981                Double.MAX_VALUE, 1));
982        assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
983                Double.POSITIVE_INFINITY, 0));
984        assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
985                Double.POSITIVE_INFINITY, -1));
986        assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb(
987                Double.NEGATIVE_INFINITY, -1));
988        assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb(
989                Double.NEGATIVE_INFINITY, Double.MIN_EXPONENT));
990
991        // result is subnormal/zero
992        long posZeroBits = Double.doubleToLongBits(+0.0);
993        long negZeroBits = Double.doubleToLongBits(-0.0);
994        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
995                +0.0, Integer.MAX_VALUE)));
996        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
997                +0.0, -123)));
998        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
999                +0.0, 0)));
1000        assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1001                -0.0, 123)));
1002        assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1003                -0.0, Integer.MIN_VALUE)));
1004
1005        assertEquals(Double.MIN_VALUE, StrictMath.scalb(1.0, -1074));
1006        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(1.0,
1007                -1075)));
1008        assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1009                -1.0, -1075)));
1010
1011        // precision lost
1012        assertEquals(StrictMath.scalb(21.405, -1078), StrictMath.scalb(21.405,
1013                -1079));
1014        assertEquals(Double.MIN_VALUE, StrictMath.scalb(21.405, -1079));
1015        assertEquals(-Double.MIN_VALUE, StrictMath.scalb(-21.405, -1079));
1016        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1017                21.405, -1080)));
1018        assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1019                -21.405, -1080)));
1020        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1021                Double.MIN_VALUE, -1)));
1022        assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1023                -Double.MIN_VALUE, -1)));
1024        assertEquals(Double.MIN_VALUE, StrictMath.scalb(Double.MIN_NORMAL, -52));
1025        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1026                Double.MIN_NORMAL, -53)));
1027        assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1028                -Double.MIN_NORMAL, -53)));
1029        assertEquals(Double.MIN_VALUE, StrictMath
1030                .scalb(Double.MAX_VALUE, -2098));
1031        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1032                Double.MAX_VALUE, -2099)));
1033        assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1034                -Double.MAX_VALUE, -2099)));
1035        assertEquals(Double.MIN_VALUE, StrictMath.scalb(Double.MIN_NORMAL / 3,
1036                -51));
1037        assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1038                Double.MIN_NORMAL / 3, -52)));
1039        assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
1040                -Double.MIN_NORMAL / 3, -52)));
1041        double subnormal = StrictMath.scalb(Double.MIN_NORMAL / 3, -25);
1042        assertEquals(2.2104123E-316, subnormal);
1043        // precision lost
1044        assertFalse(Double.MIN_NORMAL / 3 == StrictMath.scalb(subnormal, 25));
1045
1046        // NaN
1047        assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, 1)));
1048        assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, 0)));
1049        assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, -120)));
1050
1051        assertEquals(1283457024, Double.doubleToLongBits(StrictMath.scalb(
1052                Double.MIN_VALUE * 153, 23)));
1053        assertEquals(-9223372035571318784L, Double.doubleToLongBits(StrictMath
1054                .scalb(-Double.MIN_VALUE * 153, 23)));
1055        assertEquals(36908406321184768L, Double.doubleToLongBits(StrictMath
1056                .scalb(Double.MIN_VALUE * 153, 52)));
1057        assertEquals(-9186463630533591040L, Double.doubleToLongBits(StrictMath
1058                .scalb(-Double.MIN_VALUE * 153, 52)));
1059
1060        // test for exception
1061        try {
1062            StrictMath.scalb((Double) null, (Integer) null);
1063            fail("Should throw NullPointerException");
1064        } catch (NullPointerException e) {
1065            // Expected
1066        }
1067        try {
1068            StrictMath.scalb(1.0, (Integer) null);
1069            fail("Should throw NullPointerException");
1070        } catch (NullPointerException e) {
1071            // Expected
1072        }
1073        try {
1074            StrictMath.scalb((Double) null, 1);
1075            fail("Should throw NullPointerException");
1076        } catch (NullPointerException e) {
1077            // Expected
1078        }
1079    }
1080
1081    /**
1082     * @tests {@link java.lang.StrictMath#scalb(float, int)}
1083     * @since 1.6
1084     */
1085    @SuppressWarnings("boxing")
1086    public void test_scalb_FI() {
1087        // result is normal
1088        assertEquals(4.1422946304E7f, StrictMath.scalb(1.2345f, 25));
1089        assertEquals(3.679096698760986E-8f, StrictMath.scalb(1.2345f, -25));
1090        assertEquals(1.2345f, StrictMath.scalb(1.2345f, 0));
1091        assertEquals(7868514.304f, StrictMath.scalb(0.2345f, 25));
1092
1093        float normal = StrictMath.scalb(0.2345f, -25);
1094        assertEquals(6.98864459991455E-9f, normal);
1095        // precision kept
1096        assertEquals(0.2345f, StrictMath.scalb(normal, 25));
1097
1098        assertEquals(0.2345f, StrictMath.scalb(0.2345f, 0));
1099        assertEquals(-4.1422946304E7f, StrictMath.scalb(-1.2345f, 25));
1100        assertEquals(-6.98864459991455E-9f, StrictMath.scalb(-0.2345f, -25));
1101        assertEquals(2.0f, StrictMath.scalb(Float.MIN_NORMAL / 2, 128));
1102        assertEquals(64.0f, StrictMath.scalb(Float.MIN_VALUE, 155));
1103        assertEquals(34, StrictMath.getExponent(StrictMath.scalb(1.0f, 34)));
1104        assertEquals(3.9999998f, StrictMath.scalb(Float.MAX_VALUE,
1105                Float.MIN_EXPONENT));
1106
1107        // result is near infinity
1108        float halfMax = StrictMath.scalb(1.0f, Float.MAX_EXPONENT);
1109        assertEquals(1.7014118E38f, halfMax);
1110        assertEquals(Float.MAX_VALUE, halfMax - StrictMath.ulp(halfMax)
1111                + halfMax);
1112        assertEquals(Float.POSITIVE_INFINITY, halfMax + halfMax);
1113        assertEquals(3.4028233E38f, StrictMath.scalb(1.0f - StrictMath
1114                .ulp(1.0f), Float.MAX_EXPONENT + 1));
1115        assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(
1116                1.0f - StrictMath.ulp(1.0f), Float.MAX_EXPONENT + 2));
1117
1118        halfMax = StrictMath.scalb(-1.0f, Float.MAX_EXPONENT);
1119        assertEquals(-1.7014118E38f, halfMax);
1120        assertEquals(-Float.MAX_VALUE, halfMax + StrictMath.ulp(halfMax)
1121                + halfMax);
1122        assertEquals(Float.NEGATIVE_INFINITY, halfMax + halfMax);
1123
1124        assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(0.345f, 1234));
1125        assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(44.345E10f, 934));
1126        assertEquals(Float.NEGATIVE_INFINITY, StrictMath
1127                .scalb(-44.345E10f, 934));
1128
1129        assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(
1130                Float.MIN_NORMAL / 2, 400));
1131        assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(Float.MIN_VALUE,
1132                800));
1133        assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(Float.MAX_VALUE,
1134                1));
1135        assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(
1136                Float.POSITIVE_INFINITY, 0));
1137        assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(
1138                Float.POSITIVE_INFINITY, -1));
1139        assertEquals(Float.NEGATIVE_INFINITY, StrictMath.scalb(
1140                Float.NEGATIVE_INFINITY, -1));
1141        assertEquals(Float.NEGATIVE_INFINITY, StrictMath.scalb(
1142                Float.NEGATIVE_INFINITY, Float.MIN_EXPONENT));
1143
1144        // result is subnormal/zero
1145        int posZeroBits = Float.floatToIntBits(+0.0f);
1146        int negZeroBits = Float.floatToIntBits(-0.0f);
1147        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f,
1148                Integer.MAX_VALUE)));
1149        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f,
1150                -123)));
1151        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f,
1152                0)));
1153        assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-0.0f,
1154                123)));
1155        assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-0.0f,
1156                Integer.MIN_VALUE)));
1157
1158        assertEquals(Float.MIN_VALUE, StrictMath.scalb(1.0f, -149));
1159        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(1.0f,
1160                -150)));
1161        assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-1.0f,
1162                -150)));
1163
1164        // precision lost
1165        assertEquals(StrictMath.scalb(21.405f, -154), StrictMath.scalb(21.405f,
1166                -153));
1167        assertEquals(Float.MIN_VALUE, StrictMath.scalb(21.405f, -154));
1168        assertEquals(-Float.MIN_VALUE, StrictMath.scalb(-21.405f, -154));
1169        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
1170                21.405f, -155)));
1171        assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
1172                -21.405f, -155)));
1173        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
1174                Float.MIN_VALUE, -1)));
1175        assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
1176                -Float.MIN_VALUE, -1)));
1177        assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MIN_NORMAL, -23));
1178        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
1179                Float.MIN_NORMAL, -24)));
1180        assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
1181                -Float.MIN_NORMAL, -24)));
1182        assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MAX_VALUE, -277));
1183        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
1184                Float.MAX_VALUE, -278)));
1185        assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
1186                -Float.MAX_VALUE, -278)));
1187        assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MIN_NORMAL / 3,
1188                -22));
1189        assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
1190                Float.MIN_NORMAL / 3, -23)));
1191        assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
1192                -Float.MIN_NORMAL / 3, -23)));
1193        float subnormal = StrictMath.scalb(Float.MIN_NORMAL / 3, -11);
1194        assertEquals(1.913E-42f, subnormal);
1195        // precision lost
1196        assertFalse(Float.MIN_NORMAL / 3 == StrictMath.scalb(subnormal, 11));
1197
1198        assertEquals(68747264, Float.floatToIntBits(StrictMath.scalb(
1199                Float.MIN_VALUE * 153, 23)));
1200        assertEquals(-2078736384, Float.floatToIntBits(StrictMath.scalb(
1201                -Float.MIN_VALUE * 153, 23)));
1202
1203        assertEquals(4896, Float.floatToIntBits(StrictMath.scalb(
1204                Float.MIN_VALUE * 153, 5)));
1205        assertEquals(-2147478752, Float.floatToIntBits(StrictMath.scalb(
1206                -Float.MIN_VALUE * 153, 5)));
1207
1208        // NaN
1209        assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, 1)));
1210        assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, 0)));
1211        assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, -120)));
1212
1213        // test for exception
1214        try {
1215            StrictMath.scalb((Float) null, (Integer) null);
1216            fail("Should throw NullPointerException");
1217        } catch (NullPointerException e) {
1218            // Expected
1219        }
1220        try {
1221            StrictMath.scalb(1.0f, (Integer) null);
1222            fail("Should throw NullPointerException");
1223        } catch (NullPointerException e) {
1224            // Expected
1225        }
1226        try {
1227            StrictMath.scalb((Float) null, 1);
1228            fail("Should throw NullPointerException");
1229        } catch (NullPointerException e) {
1230            // Expected
1231        }
1232    }
1233
1234    /**
1235     * @tests java.lang.StrictMath#signum(double)
1236     */
1237    public void test_signum_D() {
1238        assertTrue(Double.isNaN(StrictMath.signum(Double.NaN)));
1239        assertEquals(Double.doubleToLongBits(0.0), Double
1240                .doubleToLongBits(StrictMath.signum(0.0)));
1241        assertEquals(Double.doubleToLongBits(+0.0), Double
1242                .doubleToLongBits(StrictMath.signum(+0.0)));
1243        assertEquals(Double.doubleToLongBits(-0.0), Double
1244                .doubleToLongBits(StrictMath.signum(-0.0)));
1245
1246        assertEquals(1.0, StrictMath.signum(253681.2187962), 0D);
1247        assertEquals(-1.0, StrictMath.signum(-125874693.56), 0D);
1248        assertEquals(1.0, StrictMath.signum(1.2587E-308), 0D);
1249        assertEquals(-1.0, StrictMath.signum(-1.2587E-308), 0D);
1250
1251        assertEquals(1.0, StrictMath.signum(Double.MAX_VALUE), 0D);
1252        assertEquals(1.0, StrictMath.signum(Double.MIN_VALUE), 0D);
1253        assertEquals(-1.0, StrictMath.signum(-Double.MAX_VALUE), 0D);
1254        assertEquals(-1.0, StrictMath.signum(-Double.MIN_VALUE), 0D);
1255        assertEquals(1.0, StrictMath.signum(Double.POSITIVE_INFINITY), 0D);
1256        assertEquals(-1.0, StrictMath.signum(Double.NEGATIVE_INFINITY), 0D);
1257
1258    }
1259
1260    /**
1261     * @tests java.lang.StrictMath#signum(float)
1262     */
1263    public void test_signum_F() {
1264        assertTrue(Float.isNaN(StrictMath.signum(Float.NaN)));
1265        assertEquals(Float.floatToIntBits(0.0f), Float
1266                .floatToIntBits(StrictMath.signum(0.0f)));
1267        assertEquals(Float.floatToIntBits(+0.0f), Float
1268                .floatToIntBits(StrictMath.signum(+0.0f)));
1269        assertEquals(Float.floatToIntBits(-0.0f), Float
1270                .floatToIntBits(StrictMath.signum(-0.0f)));
1271
1272        assertEquals(1.0f, StrictMath.signum(253681.2187962f), 0f);
1273        assertEquals(-1.0f, StrictMath.signum(-125874693.56f), 0f);
1274        assertEquals(1.0f, StrictMath.signum(1.2587E-11f), 0f);
1275        assertEquals(-1.0f, StrictMath.signum(-1.2587E-11f), 0f);
1276
1277        assertEquals(1.0f, StrictMath.signum(Float.MAX_VALUE), 0f);
1278        assertEquals(1.0f, StrictMath.signum(Float.MIN_VALUE), 0f);
1279        assertEquals(-1.0f, StrictMath.signum(-Float.MAX_VALUE), 0f);
1280        assertEquals(-1.0f, StrictMath.signum(-Float.MIN_VALUE), 0f);
1281        assertEquals(1.0f, StrictMath.signum(Float.POSITIVE_INFINITY), 0f);
1282        assertEquals(-1.0f, StrictMath.signum(Float.NEGATIVE_INFINITY), 0f);
1283    }
1284
1285	/**
1286     * @tests java.lang.StrictMath#sin(double)
1287     */
1288	public void test_sinD() {
1289		// Test for method double java.lang.StrictMath.sin(double)
1290		assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath
1291				.asin(OPP / HYP)) == OPP / HYP);
1292	}
1293
1294    /**
1295     * @tests java.lang.StrictMath#sinh(double)
1296     */
1297    public void test_sinh_D() {
1298        // Test for special situations
1299        assertTrue(Double.isNaN(StrictMath.sinh(Double.NaN)));
1300        assertEquals("Should return POSITIVE_INFINITY",
1301                Double.POSITIVE_INFINITY, StrictMath
1302                        .sinh(Double.POSITIVE_INFINITY), 0D);
1303        assertEquals("Should return NEGATIVE_INFINITY",
1304                Double.NEGATIVE_INFINITY, StrictMath
1305                        .sinh(Double.NEGATIVE_INFINITY), 0D);
1306        assertEquals(Double.doubleToLongBits(0.0), Double
1307				.doubleToLongBits(StrictMath.sinh(0.0)));
1308		assertEquals(Double.doubleToLongBits(+0.0), Double
1309				.doubleToLongBits(StrictMath.sinh(+0.0)));
1310		assertEquals(Double.doubleToLongBits(-0.0), Double
1311				.doubleToLongBits(StrictMath.sinh(-0.0)));
1312
1313        assertEquals("Should return POSITIVE_INFINITY",
1314                Double.POSITIVE_INFINITY, StrictMath.sinh(1234.56), 0D);
1315        assertEquals("Should return NEGATIVE_INFINITY",
1316                Double.NEGATIVE_INFINITY, StrictMath.sinh(-1234.56), 0D);
1317        assertEquals("Should return 1.0000000000001666E-6",
1318                1.0000000000001666E-6, StrictMath.sinh(0.000001), 0D);
1319        assertEquals("Should return -1.0000000000001666E-6",
1320                -1.0000000000001666E-6, StrictMath.sinh(-0.000001), 0D);
1321        assertEquals("Should return 5.115386441963859", 5.115386441963859,
1322                StrictMath.sinh(2.33482), 0D);
1323        assertEquals("Should return POSITIVE_INFINITY",
1324                Double.POSITIVE_INFINITY, StrictMath.sinh(Double.MAX_VALUE), 0D);
1325        assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
1326                .sinh(Double.MIN_VALUE), 0D);
1327    }
1328
1329	/**
1330	 * @tests java.lang.StrictMath#sqrt(double)
1331	 */
1332	public void test_sqrtD() {
1333		// Test for method double java.lang.StrictMath.sqrt(double)
1334		assertEquals("Incorrect root returned1",
1335                             2, StrictMath.sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0);
1336		assertEquals("Incorrect root returned2", 7, StrictMath.sqrt(49), 0.0);
1337	}
1338
1339	/**
1340	 * @tests java.lang.StrictMath#tan(double)
1341	 */
1342	public void test_tanD() {
1343		// Test for method double java.lang.StrictMath.tan(double)
1344		assertTrue(
1345				"Returned incorrect tangent: ",
1346				StrictMath.tan(StrictMath.atan(1.0)) <= 1.0
1347						|| StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1);
1348	}
1349
1350    /**
1351     * @tests java.lang.StrictMath#tanh(double)
1352     */
1353    public void test_tanh_D() {
1354        // Test for special situations
1355        assertTrue(Double.isNaN(StrictMath.tanh(Double.NaN)));
1356        assertEquals("Should return +1.0", +1.0, StrictMath
1357                .tanh(Double.POSITIVE_INFINITY), 0D);
1358        assertEquals("Should return -1.0", -1.0, StrictMath
1359                .tanh(Double.NEGATIVE_INFINITY), 0D);
1360        assertEquals(Double.doubleToLongBits(0.0), Double
1361				.doubleToLongBits(StrictMath.tanh(0.0)));
1362		assertEquals(Double.doubleToLongBits(+0.0), Double
1363				.doubleToLongBits(StrictMath.tanh(+0.0)));
1364		assertEquals(Double.doubleToLongBits(-0.0), Double
1365				.doubleToLongBits(StrictMath.tanh(-0.0)));
1366
1367        assertEquals("Should return 1.0", 1.0, StrictMath.tanh(1234.56), 0D);
1368        assertEquals("Should return -1.0", -1.0, StrictMath.tanh(-1234.56), 0D);
1369        assertEquals("Should return 9.999999999996666E-7",
1370                9.999999999996666E-7, StrictMath.tanh(0.000001), 0D);
1371        assertEquals("Should return 0.981422884124941", 0.981422884124941,
1372                StrictMath.tanh(2.33482), 0D);
1373        assertEquals("Should return 1.0", 1.0, StrictMath
1374                .tanh(Double.MAX_VALUE), 0D);
1375        assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
1376                .tanh(Double.MIN_VALUE), 0D);
1377    }
1378
1379	/**
1380	 * @tests java.lang.StrictMath#random()
1381	 */
1382	public void test_random() {
1383		// There isn't a place for these tests so just stick them here
1384		assertEquals("Wrong value E",
1385				4613303445314885481L, Double.doubleToLongBits(StrictMath.E));
1386		assertEquals("Wrong value PI",
1387				4614256656552045848L, Double.doubleToLongBits(StrictMath.PI));
1388
1389		for (int i = 500; i >= 0; i--) {
1390			double d = StrictMath.random();
1391			assertTrue("Generated number is out of range: " + d, d >= 0.0
1392					&& d < 1.0);
1393		}
1394	}
1395
1396	/**
1397	 * @tests java.lang.StrictMath#toRadians(double)
1398	 */
1399	public void test_toRadiansD() {
1400		for (double d = 500; d >= 0; d -= 1.0) {
1401			double converted = StrictMath.toDegrees(StrictMath.toRadians(d));
1402			assertTrue("Converted number not equal to original. d = " + d,
1403					converted >= d * 0.99999999 && converted <= d * 1.00000001);
1404		}
1405	}
1406
1407	/**
1408	 * @tests java.lang.StrictMath#toDegrees(double)
1409	 */
1410	public void test_toDegreesD() {
1411		for (double d = 500; d >= 0; d -= 1.0) {
1412			double converted = StrictMath.toRadians(StrictMath.toDegrees(d));
1413			assertTrue("Converted number not equal to original. d = " + d,
1414					converted >= d * 0.99999999 && converted <= d * 1.00000001);
1415		}
1416	}
1417
1418	/**
1419     * @tests java.lang.StrictMath#ulp(double)
1420     */
1421     @SuppressWarnings("boxing")
1422    public void test_ulp_D() {
1423        // Test for special cases
1424		assertTrue("Should return NaN", Double
1425				.isNaN(StrictMath.ulp(Double.NaN)));
1426		assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
1427				StrictMath.ulp(Double.POSITIVE_INFINITY), 0D);
1428		assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
1429				StrictMath.ulp(Double.NEGATIVE_INFINITY), 0D);
1430		assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
1431				.ulp(0.0), 0D);
1432		assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
1433				.ulp(+0.0), 0D);
1434		assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
1435				.ulp(-0.0), 0D);
1436		assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
1437				StrictMath.ulp(Double.MAX_VALUE), 0D);
1438		assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
1439				StrictMath.ulp(-Double.MAX_VALUE), 0D);
1440
1441		assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
1442				.ulp(Double.MIN_VALUE), 0D);
1443		assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
1444				.ulp(-Double.MIN_VALUE), 0D);
1445
1446		assertEquals("Returned incorrect value", 2.220446049250313E-16,
1447				StrictMath.ulp(1.0), 0D);
1448		assertEquals("Returned incorrect value", 2.220446049250313E-16,
1449				StrictMath.ulp(-1.0), 0D);
1450		assertEquals("Returned incorrect value", 2.2737367544323206E-13,
1451				StrictMath.ulp(1153.0), 0D);
1452    }
1453
1454    /**
1455	 * @tests java.lang.StrictMath#ulp(float)
1456	 */
1457    @SuppressWarnings("boxing")
1458    public void test_ulp_f() {
1459        // Test for special cases
1460    	assertTrue("Should return NaN", Float.isNaN(StrictMath.ulp(Float.NaN)));
1461		assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
1462				StrictMath.ulp(Float.POSITIVE_INFINITY), 0f);
1463		assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
1464				StrictMath.ulp(Float.NEGATIVE_INFINITY), 0f);
1465		assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
1466				.ulp(0.0f), 0f);
1467		assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
1468				.ulp(+0.0f), 0f);
1469		assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
1470				.ulp(-0.0f), 0f);
1471		assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
1472				.ulp(Float.MAX_VALUE), 0f);
1473		assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
1474				.ulp(-Float.MAX_VALUE), 0f);
1475
1476		assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
1477				.ulp(Float.MIN_VALUE), 0f);
1478		assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
1479				.ulp(-Float.MIN_VALUE), 0f);
1480
1481		assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
1482				.ulp(1.0f), 0f);
1483		assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
1484				.ulp(-1.0f), 0f);
1485		assertEquals("Returned incorrect value", 1.2207031E-4f, StrictMath
1486				.ulp(1153.0f), 0f);
1487		assertEquals("Returned incorrect value", 5.6E-45f, Math
1488				.ulp(9.403954E-38f), 0f);
1489    }
1490}
1491