MathTest.java revision a99b695964e28a5906003d40db48cbd550fbcdf4
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 dalvik.annotation.TestLevel;
21import dalvik.annotation.TestTargetNew;
22import dalvik.annotation.TestTargetClass;
23
24@TestTargetClass(Math.class)
25public class MathTest extends junit.framework.TestCase {
26
27    double HYP = Math.sqrt(2.0);
28
29    double OPP = 1.0;
30
31    double ADJ = 1.0;
32
33    /* Required to make previous preprocessor flags work - do not remove */
34    int unused = 0;
35
36    public static void assertEquals(String message, double expected, double actual, double delta) {
37        if (delta == 0D)
38            junit.framework.Assert.assertEquals(message, expected, actual, Math.ulp(expected));
39        else
40            junit.framework.Assert.assertEquals(message, expected, actual, delta);
41    }
42
43    public static void assertEquals(String message, float expected, float actual, float delta) {
44        if (delta == 0F)
45            junit.framework.Assert.assertEquals(message, expected, actual, Math.ulp(expected));
46        else
47            junit.framework.Assert.assertEquals(message, expected, actual, delta);
48    }
49
50    /**
51     * @tests java.lang.Math#abs(double)
52     */
53    @TestTargetNew(
54        level = TestLevel.COMPLETE,
55        notes = "",
56        method = "abs",
57        args = {double.class}
58    )
59    public void test_absD() {
60        // Test for method double java.lang.Math.abs(double)
61        assertTrue("Incorrect double abs value",
62                (Math.abs(-1908.8976) == 1908.8976));
63        assertTrue("Incorrect double abs value",
64                (Math.abs(1908.8976) == 1908.8976));
65        assertEquals(0.0, Math.abs(0.0));
66        assertEquals(0.0, Math.abs(-0.0));
67        assertEquals(Double.POSITIVE_INFINITY,
68                                            Math.abs(Double.POSITIVE_INFINITY));
69        assertEquals(Double.POSITIVE_INFINITY,
70                                            Math.abs(Double.NEGATIVE_INFINITY));
71
72        assertEquals(Double.NaN, Math.abs(Double.NaN));
73    }
74
75    /**
76     * @tests java.lang.Math#abs(float)
77     */
78    @TestTargetNew(
79        level = TestLevel.COMPLETE,
80        notes = "",
81        method = "abs",
82        args = {float.class}
83    )
84    public void test_absF() {
85        // Test for method float java.lang.Math.abs(float)
86        assertTrue("Incorrect float abs value",
87                (Math.abs(-1908.8976f) == 1908.8976f));
88        assertTrue("Incorrect float abs value",
89                (Math.abs(1908.8976f) == 1908.8976f));
90
91        assertEquals(0.0f, Math.abs(0.0f));
92        assertEquals(0.0f, Math.abs(-0.0f));
93        assertEquals(Float.POSITIVE_INFINITY,
94                                            Math.abs(Float.POSITIVE_INFINITY));
95        assertEquals(Float.POSITIVE_INFINITY,
96                                            Math.abs(Float.NEGATIVE_INFINITY));
97
98        assertEquals(Float.NaN, Math.abs(Float.NaN));
99    }
100
101    /**
102     * @tests java.lang.Math#abs(int)
103     */
104    @TestTargetNew(
105        level = TestLevel.COMPLETE,
106        notes = "",
107        method = "abs",
108        args = {int.class}
109    )
110    public void test_absI() {
111        // Test for method int java.lang.Math.abs(int)
112        assertTrue("Incorrect int abs value", (Math.abs(-1908897) == 1908897));
113        assertTrue("Incorrect int abs value", (Math.abs(1908897) == 1908897));
114
115        assertEquals(Integer.MIN_VALUE, Math.abs(Integer.MIN_VALUE));
116    }
117
118    /**
119     * @tests java.lang.Math#abs(long)
120     */
121    @TestTargetNew(
122        level = TestLevel.COMPLETE,
123        notes = "",
124        method = "abs",
125        args = {long.class}
126    )
127    public void test_absJ() {
128        // Test for method long java.lang.Math.abs(long)
129        assertTrue("Incorrect long abs value",
130                (Math.abs(-19088976000089L) == 19088976000089L));
131        assertTrue("Incorrect long abs value",
132                (Math.abs(19088976000089L) == 19088976000089L));
133
134        assertEquals(Long.MIN_VALUE, Math.abs(Long.MIN_VALUE));
135    }
136
137    /**
138     * @tests java.lang.Math#acos(double)
139     */
140    @TestTargetNew(
141        level = TestLevel.COMPLETE,
142        notes = "",
143        method = "acos",
144        args = {double.class}
145    )
146    public void test_acosD() {
147        // Test for method double java.lang.Math.acos(double)
148        double r = Math.cos(Math.acos(ADJ / HYP));
149        long lr = Double.doubleToLongBits(r);
150        long t = Double.doubleToLongBits(ADJ / HYP);
151        assertTrue("Returned incorrect arc cosine", lr == t || (lr + 1) == t
152                || (lr - 1) == t);
153
154        assertEquals(Double.NaN, Math.acos(Double.MAX_VALUE));
155        assertEquals(Double.NaN, Math.acos(Double.NaN));
156    }
157
158    /**
159     * @tests java.lang.Math#asin(double)
160     */
161    @TestTargetNew(
162        level = TestLevel.COMPLETE,
163        notes = "",
164        method = "asin",
165        args = {double.class}
166    )
167    public void test_asinD() {
168        // Test for method double java.lang.Math.asin(double)
169        double r = Math.sin(Math.asin(OPP / HYP));
170        long lr = Double.doubleToLongBits(r);
171        long t = Double.doubleToLongBits(OPP / HYP);
172        assertTrue("Returned incorrect arc sine", lr == t || (lr + 1) == t
173                || (lr - 1) == t);
174
175        assertEquals(Double.NaN, Math.asin(Double.MAX_VALUE));
176        assertEquals(Double.NaN, Math.asin(Double.NaN));
177        assertEquals(0, Math.asin(0), 0);
178        assertEquals(-0, Math.asin(-0), 0);
179    }
180
181    /**
182     * @tests java.lang.Math#atan(double)
183     */
184    @TestTargetNew(
185        level = TestLevel.COMPLETE,
186        notes = "",
187        method = "atan",
188        args = {double.class}
189    )
190    public void test_atanD() {
191        // Test for method double java.lang.Math.atan(double)
192        double answer = Math.tan(Math.atan(1.0));
193        assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
194                && answer >= 9.9999999999999983E-1);
195
196        assertEquals(Double.NaN, Math.atan(Double.NaN));
197        assertEquals(0.0, Math.atan(0.0), 0.0);
198        assertEquals(-0.0, Math.atan(-0.0), 0.0);
199    }
200
201    /**
202     * @tests java.lang.Math#atan2(double, double)
203     */
204    @TestTargetNew(
205        level = TestLevel.COMPLETE,
206        notes = "",
207        method = "atan2",
208        args = {double.class, double.class}
209    )
210    public void test_atan2DD() {
211        double pi = 3.141592653589793;
212        // Test for method double java.lang.Math.atan2(double, double)
213        double answer = Math.atan(Math.tan(1.0));
214        assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
215                && answer >= 9.9999999999999983E-1);
216
217        assertEquals(Double.NaN, Math.atan2(Double.NaN, 1.0));
218        assertEquals(Double.NaN, Math.atan2(1.0, Double.NaN));
219
220        assertEquals(0.0, Math.atan2(0, 1));
221        assertEquals(0.0, Math.atan2(1, Double.POSITIVE_INFINITY));
222
223        assertEquals(-0.0, Math.atan2(-0.0, 1.0));
224        assertEquals(-0.0, Math.atan2(-1.0, Double.POSITIVE_INFINITY));
225
226        assertEquals(pi, Math.atan2(0.0, -1.0));
227        assertEquals(pi, Math.atan2(1.0, Double.NEGATIVE_INFINITY));
228
229        assertEquals(-pi, Math.atan2(-0.0, -1.0));
230        assertEquals(-pi, Math.atan2(-1.0, Double.NEGATIVE_INFINITY));
231
232        assertEquals(pi/2, Math.atan2(1.0, 0.0));
233        assertEquals(pi/2, Math.atan2(1.0, -0.0));
234
235        assertEquals(pi/2, Math.atan2(Double.POSITIVE_INFINITY, 1));
236        assertEquals(pi/2, Math.atan2(Double.POSITIVE_INFINITY, -1));
237
238        assertEquals(-pi/2, Math.atan2(-1, 0));
239        assertEquals(-pi/2, Math.atan2(-1, -0));
240        assertEquals(-pi/2, Math.atan2(Double.NEGATIVE_INFINITY, 1));
241
242        assertEquals(pi/4, Math.atan2(Double.POSITIVE_INFINITY,
243                                                     Double.POSITIVE_INFINITY));
244        assertEquals(3*pi/4, Math.atan2(Double.POSITIVE_INFINITY,
245                                                     Double.NEGATIVE_INFINITY));
246        assertEquals(-pi/4, Math.atan2(Double.NEGATIVE_INFINITY,
247                                                     Double.POSITIVE_INFINITY));
248        assertEquals(-3*pi/4, Math.atan2(Double.NEGATIVE_INFINITY,
249                                                     Double.NEGATIVE_INFINITY));
250    }
251
252     /**
253     * @tests java.lang.Math#cbrt(double)
254     */
255    @TestTargetNew(
256        level = TestLevel.COMPLETE,
257        notes = "",
258        method = "cbrt",
259        args = {double.class}
260    )
261    public void test_cbrt_D() {
262        //Test for special situations
263        assertTrue("Should return Double.NaN", Double.isNaN(Math
264                .cbrt(Double.NaN)));
265        assertEquals("Should return Double.POSITIVE_INFINITY",
266                Double.POSITIVE_INFINITY, Math
267                        .cbrt(Double.POSITIVE_INFINITY), 0D);
268        assertEquals("Should return Double.NEGATIVE_INFINITY",
269                Double.NEGATIVE_INFINITY, Math
270                        .cbrt(Double.NEGATIVE_INFINITY), 0D);
271        assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
272                .cbrt(0.0)));
273        assertEquals(Double.doubleToLongBits(+0.0), Double.doubleToLongBits(Math
274                .cbrt(+0.0)));
275        assertEquals(Double.doubleToLongBits(-0.0), Double.doubleToLongBits(Math
276                .cbrt(-0.0)));
277
278        assertEquals("Should return 3.0", 3.0, Math.cbrt(27.0), 0D);
279        assertEquals("Should return 23.111993172558684", 23.111993172558684,
280                Math.cbrt(12345.6), 0D);
281        assertEquals("Should return 5.643803094122362E102",
282                5.643803094122362E102, Math.cbrt(Double.MAX_VALUE), 0D);
283        assertEquals("Should return 0.01", 0.01, Math.cbrt(0.000001), 0D);
284
285        assertEquals("Should return -3.0", -3.0, Math.cbrt(-27.0), 0D);
286        assertEquals("Should return -23.111993172558684", -23.111993172558684,
287                Math.cbrt(-12345.6), 0D);
288        assertEquals("Should return 1.7031839360032603E-108",
289                1.7031839360032603E-108, Math.cbrt(Double.MIN_VALUE), 0D);
290        assertEquals("Should return -0.01", -0.01, Math.cbrt(-0.000001), 0D);
291    }
292
293    /**
294     * @tests java.lang.Math#ceil(double)
295     */
296    @TestTargetNew(
297        level = TestLevel.COMPLETE,
298        notes = "",
299        method = "ceil",
300        args = {double.class}
301    )
302    public void test_ceilD() {
303        // Test for method double java.lang.Math.ceil(double)
304                assertEquals("Incorrect ceiling for double",
305                             79, Math.ceil(78.89), 0);
306        assertEquals("Incorrect ceiling for double",
307                             -78, Math.ceil(-78.89), 0);
308
309        assertEquals("Incorrect ceiling for double",
310                -78, Math.ceil(-78), 0);
311
312        double [] args = {0.0, -0.0, Double.NaN, Double.POSITIVE_INFINITY,
313                Double.NEGATIVE_INFINITY};
314        for(int i = 0; i < args.length; i++) {
315            assertEquals(args[i], Math.ceil(args[i]));
316        }
317        assertEquals(-0.0, Math.ceil(-0.5));
318    }
319
320    /**
321     * @tests java.lang.Math#cos(double)
322     */
323    @TestTargetNew(
324        level = TestLevel.COMPLETE,
325        notes = "",
326        method = "cos",
327        args = {double.class}
328    )
329    public void test_cosD() {
330        // Test for method double java.lang.Math.cos(double)
331        assertEquals("Incorrect answer", 1.0, Math.cos(0), 0D);
332        assertEquals("Incorrect answer", 0.5403023058681398, Math.cos(1), 0D);
333        double [] args = {Double.NaN, Double.POSITIVE_INFINITY,
334                          Double.NEGATIVE_INFINITY};
335        for(int i = 0; i < args.length; i++) {
336            assertEquals(args[i], Math.ceil(args[i]));
337        }
338    }
339
340    /**
341     * @tests java.lang.Math#cosh(double)
342     */
343    @TestTargetNew(
344        level = TestLevel.COMPLETE,
345        notes = "",
346        method = "cosh",
347        args = {double.class}
348    )
349    public void test_cosh_D() {
350        // Test for special situations
351        assertTrue(Double.isNaN(Math.cosh(Double.NaN)));
352        assertEquals("Should return POSITIVE_INFINITY",
353                Double.POSITIVE_INFINITY, Math.cosh(Double.POSITIVE_INFINITY), 0D);
354        assertEquals("Should return POSITIVE_INFINITY",
355                Double.POSITIVE_INFINITY, Math.cosh(Double.NEGATIVE_INFINITY), 0D);
356        assertEquals("Should return 1.0", 1.0, Math.cosh(+0.0), 0D);
357        assertEquals("Should return 1.0", 1.0, Math.cosh(-0.0), 0D);
358
359        assertEquals("Should return POSITIVE_INFINITY",
360                Double.POSITIVE_INFINITY, Math.cosh(1234.56), 0D);
361        assertEquals("Should return POSITIVE_INFINITY",
362                Double.POSITIVE_INFINITY, Math.cosh(-1234.56), 0D);
363        assertEquals("Should return 1.0000000000005", 1.0000000000005, Math
364                .cosh(0.000001), 0D);
365        assertEquals("Should return 1.0000000000005", 1.0000000000005, Math
366                .cosh(-0.000001), 0D);
367        assertEquals("Should return 5.212214351945598", 5.212214351945598, Math
368                .cosh(2.33482), 0D);
369
370        assertEquals("Should return POSITIVE_INFINITY",
371                Double.POSITIVE_INFINITY, Math.cosh(Double.MAX_VALUE), 0D);
372        assertEquals("Should return 1.0", 1.0, Math.cosh(Double.MIN_VALUE), 0D);
373    }
374
375    /**
376     * @tests java.lang.Math#exp(double)
377     */
378    @TestTargetNew(
379        level = TestLevel.COMPLETE,
380        notes = "",
381        method = "exp",
382        args = {double.class}
383    )
384    public void test_expD() {
385        // Test for method double java.lang.Math.exp(double)
386        assertTrue("Incorrect answer returned for simple power", Math.abs(Math
387                .exp(4D)
388                - Math.E * Math.E * Math.E * Math.E) < 0.1D);
389        assertTrue("Incorrect answer returned for larger power", Math.log(Math
390                .abs(Math.exp(5.5D)) - 5.5D) < 10.0D);
391
392        assertEquals("Incorrect returned value for NaN",
393                                              Double.NaN, Math.exp(Double.NaN));
394        assertEquals("Incorrect returned value for positive infinity",
395                  Double.POSITIVE_INFINITY, Math.exp(Double.POSITIVE_INFINITY));
396        assertEquals("Incorrect returned value for negative infinity",
397                                      0, Math.exp(Double.NEGATIVE_INFINITY), 0);
398    }
399
400    /**
401     * @tests java.lang.Math#expm1(double)
402     */
403    @TestTargetNew(
404        level = TestLevel.COMPLETE,
405        notes = "",
406        method = "expm1",
407        args = {double.class}
408    )
409    public void test_expm1_D() {
410        // Test for special cases
411        assertTrue("Should return NaN", Double.isNaN(Math.expm1(Double.NaN)));
412        assertEquals("Should return POSITIVE_INFINITY",
413                Double.POSITIVE_INFINITY, Math.expm1(Double.POSITIVE_INFINITY), 0D);
414        assertEquals("Should return -1.0", -1.0, Math
415                .expm1(Double.NEGATIVE_INFINITY), 0D);
416        assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
417                .expm1(0.0)));
418        assertEquals(Double.doubleToLongBits(+0.0), Double
419                .doubleToLongBits(Math.expm1(+0.0)));
420        assertEquals(Double.doubleToLongBits(-0.0), Double
421                .doubleToLongBits(Math.expm1(-0.0)));
422
423        assertEquals("Should return -9.999950000166666E-6",
424                -9.999950000166666E-6, Math.expm1(-0.00001), 0D);
425        assertEquals("Should return 1.0145103074469635E60",
426                1.0145103074469635E60, Math.expm1(138.16951162), 0D);
427        assertEquals("Should return POSITIVE_INFINITY",
428                Double.POSITIVE_INFINITY, Math
429                        .expm1(123456789123456789123456789.4521584223), 0D);
430        assertEquals("Should return POSITIVE_INFINITY",
431                Double.POSITIVE_INFINITY, Math.expm1(Double.MAX_VALUE), 0D);
432        assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, Math
433                .expm1(Double.MIN_VALUE), 0D);
434    }
435
436    /**
437     * @tests java.lang.Math#floor(double)
438     */
439    @TestTargetNew(
440        level = TestLevel.COMPLETE,
441        notes = "",
442        method = "floor",
443        args = {double.class}
444    )
445    public void test_floorD() {
446        // Test for method double java.lang.Math.floor(double)
447                assertEquals("Incorrect floor for double",
448                             78, Math.floor(78.89), 0);
449        assertEquals("Incorrect floor for double",
450                             -79, Math.floor(-78.89), 0);
451        assertEquals("Incorrect floor for integer",
452                              -78, Math.floor(-78), 0);
453        double [] args = {0, -0, Double.NaN, Double.POSITIVE_INFINITY,
454                Double.NEGATIVE_INFINITY};
455        for(int i = 0; i < args.length; i++) {
456            assertEquals(args[i], Math.floor(args[i]));
457        }
458    }
459
460    /**
461     * @tests java.lang.Math#hypot(double, double)
462     */
463    @TestTargetNew(
464        level = TestLevel.COMPLETE,
465        notes = "",
466        method = "hypot",
467        args = {double.class, double.class}
468    )
469    public void test_hypot_DD() {
470        // Test for special cases
471        assertEquals("Should return POSITIVE_INFINITY",
472                Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY,
473                        1.0), 0D);
474        assertEquals("Should return POSITIVE_INFINITY",
475                Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
476                        123.324), 0D);
477        assertEquals("Should return POSITIVE_INFINITY",
478                Double.POSITIVE_INFINITY, Math.hypot(-758.2587,
479                        Double.POSITIVE_INFINITY), 0D);
480        assertEquals("Should return POSITIVE_INFINITY",
481                Double.POSITIVE_INFINITY, Math.hypot(5687.21,
482                        Double.NEGATIVE_INFINITY), 0D);
483        assertEquals("Should return POSITIVE_INFINITY",
484                Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY,
485                        Double.NEGATIVE_INFINITY), 0D);
486        assertEquals("Should return POSITIVE_INFINITY",
487                Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
488                        Double.POSITIVE_INFINITY), 0D);
489        assertTrue("Should be NaN", Double.isNaN(Math.hypot(Double.NaN,
490                2342301.89843)));
491        assertTrue("Should be NaN", Double.isNaN(Math.hypot(-345.2680,
492                Double.NaN)));
493
494        assertEquals("Should return 2396424.905416697", 2396424.905416697, Math
495                .hypot(12322.12, -2396393.2258), 0D);
496        assertEquals("Should return 138.16958070558556", 138.16958070558556,
497                Math.hypot(-138.16951162, 0.13817035864), 0D);
498        assertEquals("Should return 1.7976931348623157E308",
499                1.7976931348623157E308, Math.hypot(Double.MAX_VALUE, 211370.35), 0D);
500        assertEquals("Should return 5413.7185", 5413.7185, Math.hypot(
501                -5413.7185, Double.MIN_VALUE), 0D);
502    }
503
504    /**
505     * @tests java.lang.Math#IEEEremainder(double, double)
506     */
507    @TestTargetNew(
508        level = TestLevel.COMPLETE,
509        notes = "",
510        method = "IEEEremainder",
511        args = {double.class, double.class}
512    )
513    public void test_IEEEremainderDD() {
514        // Test for method double java.lang.Math.IEEEremainder(double, double)
515        assertEquals("Incorrect remainder returned",
516                0.0, Math.IEEEremainder(1.0, 1.0), 0D);
517        assertTrue("Incorrect remainder returned", Math.IEEEremainder(1.32,
518                89.765) >= 1.4705063220631647E-2
519                || Math.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
520
521        assertEquals(Double.NaN, Math.IEEEremainder(Double.NaN, Double.NaN));
522        assertEquals(Double.NaN, Math.IEEEremainder(Double.NaN, 1.0));
523        assertEquals(Double.NaN, Math.IEEEremainder(1.0, Double.NaN));
524
525        assertEquals(Double.NaN, Math.IEEEremainder(Double.POSITIVE_INFINITY, 1.0));
526        assertEquals(Double.NaN, Math.IEEEremainder(Double.NEGATIVE_INFINITY, 1.0));
527        assertEquals(1.0, Math.IEEEremainder(1.0, Double.POSITIVE_INFINITY));
528        assertEquals(1.0, Math.IEEEremainder(1.0, Double.NEGATIVE_INFINITY));
529        assertEquals(Double.NaN, Math.IEEEremainder(1.0, 0.0));
530        assertEquals(Double.NaN, Math.IEEEremainder(1.0, -0.0));
531    }
532
533    /**
534     * @tests java.lang.Math#log(double)
535     */
536    @TestTargetNew(
537        level = TestLevel.COMPLETE,
538        notes = "",
539        method = "log",
540        args = {double.class}
541    )
542    public void test_logD() {
543        // Test for method double java.lang.Math.log(double)
544        for (double d = 10; d >= -10; d -= 0.5) {
545            double answer = Math.log(Math.exp(d));
546            assertTrue("Answer does not equal expected answer for d = " + d
547                    + " answer = " + answer, Math.abs(answer - d) <= Math
548                    .abs(d * 0.00000001));
549        }
550    }
551
552    /**
553     * @tests java.lang.Math#log10(double)
554     */
555    @TestTargetNew(
556        level = TestLevel.COMPLETE,
557        notes = "",
558        method = "log10",
559        args = {double.class}
560    )
561    @SuppressWarnings("boxing")
562    public void test_log10_D() {
563        // Test for special cases
564        assertTrue(Double.isNaN(Math.log10(Double.NaN)));
565        assertTrue(Double.isNaN(Math.log10(-2541.05745687234187532)));
566        assertTrue(Double.isNaN(Math.log10(-0.1)));
567        assertEquals(Double.POSITIVE_INFINITY, Math.log10(Double.POSITIVE_INFINITY));
568        assertEquals(Double.NEGATIVE_INFINITY, Math.log10(0.0));
569        assertEquals(Double.NEGATIVE_INFINITY, Math.log10(+0.0));
570        assertEquals(Double.NEGATIVE_INFINITY, Math.log10(-0.0));
571
572        assertEquals(3.0, Math.log10(1000.0));
573        assertEquals(14.0, Math.log10(Math.pow(10, 14)));
574        assertEquals(3.7389561269540406, Math.log10(5482.2158));
575        assertEquals(14.661551142893833, Math.log10(458723662312872.125782332587));
576        assertEquals(-0.9083828622192334, Math.log10(0.12348583358871));
577        assertEquals(308.25471555991675, Math.log10(Double.MAX_VALUE));
578        assertEquals(-323.3062153431158, Math.log10(Double.MIN_VALUE));
579    }
580
581    /**
582     * @tests java.lang.Math#log1p(double)
583     */
584    @TestTargetNew(
585        level = TestLevel.COMPLETE,
586        notes = "",
587        method = "log1p",
588        args = {double.class}
589    )
590    public void test_log1p_D() {
591        // Test for special cases
592        assertTrue("Should return NaN", Double.isNaN(Math.log1p(Double.NaN)));
593        assertTrue("Should return NaN", Double.isNaN(Math.log1p(-32.0482175)));
594        assertEquals("Should return POSITIVE_INFINITY",
595                Double.POSITIVE_INFINITY, Math.log1p(Double.POSITIVE_INFINITY), 0D);
596        assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
597                .log1p(0.0)));
598        assertEquals(Double.doubleToLongBits(+0.0), Double
599                .doubleToLongBits(Math.log1p(+0.0)));
600        assertEquals(Double.doubleToLongBits(-0.0), Double
601                .doubleToLongBits(Math.log1p(-0.0)));
602
603        assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
604                Math.log1p(-0.254856327), 0D);
605        assertEquals("Should return 7.368050685564151", 7.368050685564151, Math
606                .log1p(1583.542), 0D);
607        assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
608                Math.log1p(0.5894227), 0D);
609        assertEquals("Should return 709.782712893384", 709.782712893384, Math
610                .log1p(Double.MAX_VALUE), 0D);
611        assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, Math
612                .log1p(Double.MIN_VALUE), 0D);
613    }
614
615    /**
616     * @tests java.lang.Math#max(double, double)
617     */
618    @TestTargetNew(
619        level = TestLevel.COMPLETE,
620        notes = "",
621        method = "max",
622        args = {double.class, double.class}
623    )
624    public void test_maxDD() {
625        // Test for method double java.lang.Math.max(double, double)
626        assertEquals("Incorrect double max value", 1908897.6000089,
627                Math.max(-1908897.6000089,
628                1908897.6000089), 0D);
629        assertEquals("Incorrect double max value",
630                1908897.6000089, Math.max(2.0, 1908897.6000089), 0D);
631        assertEquals("Incorrect double max value", -2.0, Math.max(-2.0,
632                -1908897.6000089), 0D);
633
634        assertEquals("Incorrect returned value", Double.NaN,
635                                                Math.max(-1.0, Double.NaN));
636        assertEquals("Incorrect returned value", Double.NaN,
637                                                Math.max(Double.NaN, -1.0));
638        assertEquals("Incorrect returned value", 0, Math.max(0, -0), 0D);
639    }
640
641    /**
642     * @tests java.lang.Math#max(float, float)
643     */
644    @TestTargetNew(
645        level = TestLevel.COMPLETE,
646        notes = "",
647        method = "max",
648        args = {float.class, float.class}
649    )
650    public void test_maxFF() {
651        // Test for method float java.lang.Math.max(float, float)
652        assertTrue("Incorrect float max value", Math.max(-1908897.600f,
653                1908897.600f) == 1908897.600f);
654        assertTrue("Incorrect float max value",
655                Math.max(2.0f, 1908897.600f) == 1908897.600f);
656        assertTrue("Incorrect float max value",
657                Math.max(-2.0f, -1908897.600f) == -2.0f);
658        assertEquals("Incorrect returned value", Float.NaN,
659                Math.max(-1.0f, Float.NaN));
660        assertEquals("Incorrect returned value", Float.NaN,
661                Math.max(Float.NaN, -1.0f));
662        assertEquals("Incorrect returned value", 0f, Math.max(0f, -0f));
663    }
664
665    /**
666     * @tests java.lang.Math#max(int, int)
667     */
668    @TestTargetNew(
669        level = TestLevel.COMPLETE,
670        notes = "",
671        method = "max",
672        args = {int.class, int.class}
673    )
674    public void test_maxII() {
675        // Test for method int java.lang.Math.max(int, int)
676        assertEquals("Incorrect int max value",
677                19088976, Math.max(-19088976, 19088976));
678        assertEquals("Incorrect int max value",
679                19088976, Math.max(20, 19088976));
680        assertEquals("Incorrect int max value", -20, Math.max(-20, -19088976));
681    }
682
683    /**
684     * @tests java.lang.Math#max(long, long)
685     */
686    @TestTargetNew(
687        level = TestLevel.COMPLETE,
688        notes = "",
689        method = "max",
690        args = {long.class, long.class}
691    )
692    public void test_maxJJ() {
693        // Test for method long java.lang.Math.max(long, long)
694        assertEquals("Incorrect long max value", 19088976000089L, Math.max(-19088976000089L,
695                19088976000089L));
696        assertEquals("Incorrect long max value",
697                19088976000089L, Math.max(20, 19088976000089L));
698        assertEquals("Incorrect long max value",
699                -20, Math.max(-20, -19088976000089L));
700    }
701
702    /**
703     * @tests java.lang.Math#min(double, double)
704     */
705    @TestTargetNew(
706        level = TestLevel.COMPLETE,
707        notes = "",
708        method = "min",
709        args = {double.class, double.class}
710    )
711    public void test_minDD() {
712        // Test for method double java.lang.Math.min(double, double)
713        assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-1908897.6000089,
714                1908897.6000089), 0D);
715        assertEquals("Incorrect double min value",
716                2.0, Math.min(2.0, 1908897.6000089), 0D);
717        assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-2.0,
718                -1908897.6000089), 0D);
719        assertEquals("Incorrect returned value", Double.NaN,
720                Math.min(-1.0, Double.NaN));
721        assertEquals("Incorrect returned value", Double.NaN,
722                Math.min(Double.NaN, -1.0));
723        assertEquals("Incorrect returned value", -0.0, Math.min(0.0, -0.0));
724    }
725
726    /**
727     * @tests java.lang.Math#min(float, float)
728     */
729    @TestTargetNew(
730        level = TestLevel.COMPLETE,
731        notes = "",
732        method = "min",
733        args = {float.class, float.class}
734    )
735    public void test_minFF() {
736        // Test for method float java.lang.Math.min(float, float)
737        assertTrue("Incorrect float min value", Math.min(-1908897.600f,
738                1908897.600f) == -1908897.600f);
739        assertTrue("Incorrect float min value",
740                Math.min(2.0f, 1908897.600f) == 2.0f);
741        assertTrue("Incorrect float min value",
742                Math.min(-2.0f, -1908897.600f) == -1908897.600f);
743        assertEquals("Incorrect returned value", Float.NaN,
744                Math.min(-1.0f, Float.NaN));
745        assertEquals("Incorrect returned value", Float.NaN,
746                Math.min(Float.NaN, -1.0f));
747        assertEquals("Incorrect returned value", -0f, Math.min(0f, -0f));
748    }
749
750    /**
751     * @tests java.lang.Math#min(int, int)
752     */
753    @TestTargetNew(
754        level = TestLevel.COMPLETE,
755        notes = "",
756        method = "min",
757        args = {int.class, int.class}
758    )
759    public void test_minII() {
760        // Test for method int java.lang.Math.min(int, int)
761        assertEquals("Incorrect int min value",
762                -19088976, Math.min(-19088976, 19088976));
763        assertEquals("Incorrect int min value", 20, Math.min(20, 19088976));
764        assertEquals("Incorrect int min value",
765                -19088976, Math.min(-20, -19088976));
766
767    }
768
769    /**
770     * @tests java.lang.Math#min(long, long)
771     */
772    @TestTargetNew(
773        level = TestLevel.COMPLETE,
774        notes = "",
775        method = "min",
776        args = {long.class, long.class}
777    )
778    public void test_minJJ() {
779        // Test for method long java.lang.Math.min(long, long)
780        assertEquals("Incorrect long min value", -19088976000089L, Math.min(-19088976000089L,
781                19088976000089L));
782        assertEquals("Incorrect long min value",
783                20, Math.min(20, 19088976000089L));
784        assertEquals("Incorrect long min value",
785                -19088976000089L, Math.min(-20, -19088976000089L));
786    }
787
788    /**
789     * @tests java.lang.Math#pow(double, double)
790     */
791    @TestTargetNew(
792        level = TestLevel.COMPLETE,
793        notes = "",
794        method = "pow",
795        args = {double.class, double.class}
796    )
797    public void test_powDD() {
798        // Test for method double java.lang.Math.pow(double, double)
799        assertTrue("pow returned incorrect value",
800                (long) Math.pow(2, 8) == 256l);
801        assertTrue("pow returned incorrect value",
802                Math.pow(2, -8) == 0.00390625d);
803        assertEquals("Incorrect root returned1",
804                             2, Math.sqrt(Math.pow(Math.sqrt(2), 4)), 0);
805
806        assertEquals("pow returned incorrect value", 1.0, Math.pow(1, 0));
807        assertEquals("pow returned incorrect value", 2.0, Math.pow(2, 1));
808        assertEquals("pow returned incorrect value", Double.NaN,
809                                        Math.pow(Double.MAX_VALUE, Double.NaN));
810        assertEquals("pow returned incorrect value", Double.NaN,
811                                        Math.pow(Double.NaN, Double.MAX_VALUE));
812        assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY,
813                                       Math.pow(1.1, Double.POSITIVE_INFINITY));
814        assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY,
815                                       Math.pow(0.9, Double.NEGATIVE_INFINITY));
816
817        assertEquals("pow returned incorrect value", 0.0,
818                                       Math.pow(1.1, Double.NEGATIVE_INFINITY));
819        assertEquals("pow returned incorrect value", 0.0,
820                                       Math.pow(0.9, Double.POSITIVE_INFINITY));
821
822        assertEquals("pow returned incorrect value", Double.NaN,
823                                       Math.pow(1.0, Double.NEGATIVE_INFINITY));
824        assertEquals("pow returned incorrect value", Double.NaN,
825                                       Math.pow(1.0, Double.POSITIVE_INFINITY));
826
827        assertEquals("pow returned incorrect value", 0.0, Math.pow(0, 1));
828        assertEquals("pow returned incorrect value", 0.0,
829                                      Math.pow(Double.POSITIVE_INFINITY, -0.1));
830
831        assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY,
832                                                               Math.pow(0, -1));
833        assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY,
834                                         Math.pow(Double.POSITIVE_INFINITY, 1));
835
836        assertEquals("pow returned incorrect value", 0.0,
837                                                           Math.pow(-0.0, 0.9));
838        assertEquals("pow returned incorrect value", 0.0,
839                                      Math.pow(Double.NEGATIVE_INFINITY, -0.9));
840
841        assertEquals("pow returned incorrect value", -0.0,
842                                                             Math.pow(-0.0, 1));
843        assertEquals("pow returned incorrect value", -0.0,
844                                        Math.pow(Double.NEGATIVE_INFINITY, -1));
845
846        assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY,
847                                                          Math.pow(-0.0, -0.9));
848        assertEquals("pow returned incorrect value", Double.POSITIVE_INFINITY,
849                                       Math.pow(Double.NEGATIVE_INFINITY, 0.9));
850
851        assertEquals("pow returned incorrect value", Double.NEGATIVE_INFINITY,
852                                                            Math.pow(-0.0, -1));
853        assertEquals("pow returned incorrect value", Double.NEGATIVE_INFINITY,
854                                         Math.pow(Double.NEGATIVE_INFINITY, 1));
855
856        assertEquals("pow returned incorrect value", 0.81, Math.pow(-0.9, 2));
857        assertEquals("pow returned incorrect value", -0.9, Math.pow(-0.9, 1));
858        assertEquals("pow returned incorrect value", Double.NaN,
859                                                           Math.pow(-0.9, 0.1));
860    }
861
862    /**
863     * @tests java.lang.Math#rint(double)
864     */
865    @TestTargetNew(
866        level = TestLevel.COMPLETE,
867        notes = "",
868        method = "rint",
869        args = {double.class}
870    )
871    public void test_rintD() {
872        // Test for method double java.lang.Math.rint(double)
873        assertEquals("Failed to round properly - up to odd",
874                3.0, Math.rint(2.9), 0D);
875        assertTrue("Failed to round properly - NaN", Double.isNaN(Math
876                .rint(Double.NaN)));
877        assertEquals("Failed to round properly down  to even",
878                2.0, Math.rint(2.1), 0D);
879        assertTrue("Failed to round properly " + 2.5 + " to even", Math
880                .rint(2.5) == 2.0);
881    }
882
883    /**
884     * @tests java.lang.Math#round(double)
885     */
886    @TestTargetNew(
887        level = TestLevel.COMPLETE,
888        notes = "",
889        method = "round",
890        args = {double.class}
891    )
892    public void test_roundD() {
893        // Test for method long java.lang.Math.round(double)
894        assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89d));
895        assertEquals("Incorrect rounding of a float", 0,
896                                                        Math.round(Double.NaN));
897        assertEquals("Incorrect rounding of a float", Long.MIN_VALUE,
898                                          Math.round(Double.NEGATIVE_INFINITY));
899        assertEquals("Incorrect rounding of a float", Long.MAX_VALUE,
900                                          Math.round(Double.POSITIVE_INFINITY));
901    }
902
903    /**
904     * @tests java.lang.Math#round(float)
905     */
906    @TestTargetNew(
907        level = TestLevel.COMPLETE,
908        notes = "",
909        method = "round",
910        args = {float.class}
911    )
912    public void test_roundF() {
913        // Test for method int java.lang.Math.round(float)
914        assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89f));
915        assertEquals("Incorrect rounding of a float", 0,
916                                                        Math.round(Float.NaN));
917        assertEquals("Incorrect rounding of a float", Integer.MIN_VALUE,
918                                          Math.round(Float.NEGATIVE_INFINITY));
919        assertEquals("Incorrect rounding of a float", Integer.MAX_VALUE,
920                                          Math.round(Float.POSITIVE_INFINITY));
921    }
922
923    /**
924     * @tests java.lang.Math#signum(double)
925     */
926    @TestTargetNew(
927        level = TestLevel.COMPLETE,
928        notes = "",
929        method = "signum",
930        args = {double.class}
931    )
932    public void test_signum_D() {
933        assertTrue(Double.isNaN(Math.signum(Double.NaN)));
934        assertTrue(Double.isNaN(Math.signum(Double.NaN)));
935        assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
936                .signum(0.0)));
937        assertEquals(Double.doubleToLongBits(+0.0), Double
938                .doubleToLongBits(Math.signum(+0.0)));
939        assertEquals(Double.doubleToLongBits(-0.0), Double
940                .doubleToLongBits(Math.signum(-0.0)));
941
942        assertEquals(1.0, Math.signum(253681.2187962), 0D);
943        assertEquals(-1.0, Math.signum(-125874693.56), 0D);
944        assertEquals(1.0, Math.signum(1.2587E-308), 0D);
945        assertEquals(-1.0, Math.signum(-1.2587E-308), 0D);
946
947        assertEquals(1.0, Math.signum(Double.MAX_VALUE), 0D);
948        assertEquals(1.0, Math.signum(Double.MIN_VALUE), 0D);
949        assertEquals(-1.0, Math.signum(-Double.MAX_VALUE), 0D);
950        assertEquals(-1.0, Math.signum(-Double.MIN_VALUE), 0D);
951        assertEquals(1.0, Math.signum(Double.POSITIVE_INFINITY), 0D);
952        assertEquals(-1.0, Math.signum(Double.NEGATIVE_INFINITY), 0D);
953    }
954
955    /**
956     * @tests java.lang.Math#signum(float)
957     */
958    @TestTargetNew(
959        level = TestLevel.COMPLETE,
960        notes = "",
961        method = "signum",
962        args = {float.class}
963    )
964    public void test_signum_F() {
965        assertTrue(Float.isNaN(Math.signum(Float.NaN)));
966        assertEquals(Float.floatToIntBits(0.0f), Float
967                .floatToIntBits(Math.signum(0.0f)));
968        assertEquals(Float.floatToIntBits(+0.0f), Float
969                .floatToIntBits(Math.signum(+0.0f)));
970        assertEquals(Float.floatToIntBits(-0.0f), Float
971                .floatToIntBits(Math.signum(-0.0f)));
972
973        assertEquals(1.0f, Math.signum(253681.2187962f), 0f);
974        assertEquals(-1.0f, Math.signum(-125874693.56f), 0f);
975        assertEquals(1.0f, Math.signum(1.2587E-11f), 0f);
976        assertEquals(-1.0f, Math.signum(-1.2587E-11f), 0f);
977
978        assertEquals(1.0f, Math.signum(Float.MAX_VALUE), 0f);
979        assertEquals(1.0f, Math.signum(Float.MIN_VALUE), 0f);
980        assertEquals(-1.0f, Math.signum(-Float.MAX_VALUE), 0f);
981        assertEquals(-1.0f, Math.signum(-Float.MIN_VALUE), 0f);
982        assertEquals(1.0f, Math.signum(Float.POSITIVE_INFINITY), 0f);
983        assertEquals(-1.0f, Math.signum(Float.NEGATIVE_INFINITY), 0f);
984    }
985
986    /**
987     * @tests java.lang.Math#sin(double)
988     */
989    @TestTargetNew(
990        level = TestLevel.COMPLETE,
991        notes = "",
992        method = "sin",
993        args = {double.class}
994    )
995    public void test_sinD() {
996        // Test for method double java.lang.Math.sin(double)
997        assertEquals("Incorrect answer", 0.0, Math.sin(0), 0D);
998        assertEquals("Incorrect answer", 0.8414709848078965, Math.sin(1), 0D);
999
1000        double [] args = {Double.NaN, Double.POSITIVE_INFINITY,
1001                          Double.NEGATIVE_INFINITY};
1002        for(int i = 0; i < args.length; i++) {
1003            assertEquals("Incorrest returned value.", Double.NaN,
1004                                                             Math.sin(args[i]));
1005        }
1006
1007        assertEquals("Incorrest returned value.", 0.0, Math.sin(0.0));
1008        assertEquals("Incorrest returned value.", -0.0, Math.sin(-0.0));
1009    }
1010
1011    /**
1012     * @tests java.lang.Math#sinh(double)
1013     */
1014    @TestTargetNew(
1015        level = TestLevel.COMPLETE,
1016        notes = "",
1017        method = "sinh",
1018        args = {double.class}
1019    )
1020    public void test_sinh_D() {
1021        // Test for special situations
1022        assertTrue("Should return NaN", Double.isNaN(Math.sinh(Double.NaN)));
1023        assertEquals("Should return POSITIVE_INFINITY",
1024                Double.POSITIVE_INFINITY, Math.sinh(Double.POSITIVE_INFINITY), 0D);
1025        assertEquals("Should return NEGATIVE_INFINITY",
1026                Double.NEGATIVE_INFINITY, Math.sinh(Double.NEGATIVE_INFINITY), 0D);
1027        assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
1028                .sinh(0.0)));
1029        assertEquals(Double.doubleToLongBits(+0.0), Double
1030                .doubleToLongBits(Math.sinh(+0.0)));
1031        assertEquals(Double.doubleToLongBits(-0.0), Double
1032                .doubleToLongBits(Math.sinh(-0.0)));
1033
1034        assertEquals("Should return POSITIVE_INFINITY",
1035                Double.POSITIVE_INFINITY, Math.sinh(1234.56), 0D);
1036        assertEquals("Should return NEGATIVE_INFINITY",
1037                Double.NEGATIVE_INFINITY, Math.sinh(-1234.56), 0D);
1038        assertEquals("Should return 1.0000000000001666E-6",
1039                1.0000000000001666E-6, Math.sinh(0.000001), 0D);
1040        assertEquals("Should return -1.0000000000001666E-6",
1041                -1.0000000000001666E-6, Math.sinh(-0.000001), 0D);
1042        assertEquals("Should return 5.115386441963859", 5.115386441963859, Math
1043                .sinh(2.33482), 0D);
1044        assertEquals("Should return POSITIVE_INFINITY",
1045                Double.POSITIVE_INFINITY, Math.sinh(Double.MAX_VALUE), 0D);
1046        assertEquals("Should return 4.9E-324", 4.9E-324, Math
1047                .sinh(Double.MIN_VALUE), 0D);
1048    }
1049
1050    /**
1051     * @tests java.lang.Math#sqrt(double)
1052     */
1053    @TestTargetNew(
1054        level = TestLevel.COMPLETE,
1055        notes = "",
1056        method = "sqrt",
1057        args = {double.class}
1058    )
1059    public void test_sqrtD() {
1060        // Test for method double java.lang.Math.sqrt(double)
1061        assertEquals("Incorrect root returned2", 7, Math.sqrt(49), 0);
1062        assertEquals("Incorrect value is returned", Double.NaN,
1063                                                         Math.sqrt(Double.NaN));
1064        assertEquals("Incorrect value is returned", Double.NaN,
1065                                                                 Math.sqrt(-1));
1066        assertEquals("Incorrect value is returned", Double.POSITIVE_INFINITY,
1067                                           Math.sqrt(Double.POSITIVE_INFINITY));
1068        assertEquals("Incorrect value is returned", 0.0, Math.sqrt(0.0));
1069        assertEquals("Incorrect value is returned", -0.0, Math.sqrt(-0.0));
1070    }
1071
1072    /**
1073     * @tests java.lang.Math#tan(double)
1074     */
1075    @TestTargetNew(
1076        level = TestLevel.COMPLETE,
1077        notes = "",
1078        method = "tan",
1079        args = {double.class}
1080    )
1081    public void test_tanD() {
1082        // Test for method double java.lang.Math.tan(double)
1083        assertEquals("Incorrect answer", 0.0, Math.tan(0), 0D);
1084        assertEquals("Incorrect answer", 1.5574077246549023, Math.tan(1), 0D);
1085
1086        double [] args = {Double.NaN, Double.POSITIVE_INFINITY,
1087                                                      Double.NEGATIVE_INFINITY};
1088        for(int i = 0; i < args.length; i++) {
1089            assertEquals("Incorrest returned value.", Double.NaN,
1090                                                   Math.tan(args[i]));
1091        }
1092
1093        assertEquals("Incorrest returned value.", 0.0, Math.tan(0.0));
1094        assertEquals("Incorrest returned value.", -0.0, Math.tan(-0.0));
1095    }
1096
1097    /**
1098     * @tests java.lang.Math#tanh(double)
1099     */
1100    @TestTargetNew(
1101        level = TestLevel.COMPLETE,
1102        notes = "",
1103        method = "tanh",
1104        args = {double.class}
1105    )
1106    public void test_tanh_D() {
1107        // Test for special situations
1108        assertTrue("Should return NaN", Double.isNaN(Math.tanh(Double.NaN)));
1109        assertEquals("Should return +1.0", +1.0, Math
1110                .tanh(Double.POSITIVE_INFINITY), 0D);
1111        assertEquals("Should return -1.0", -1.0, Math
1112                .tanh(Double.NEGATIVE_INFINITY), 0D);
1113        assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
1114                .tanh(0.0)));
1115        assertEquals(Double.doubleToLongBits(+0.0), Double
1116                .doubleToLongBits(Math.tanh(+0.0)));
1117        assertEquals(Double.doubleToLongBits(-0.0), Double
1118                .doubleToLongBits(Math.tanh(-0.0)));
1119
1120        assertEquals("Should return 1.0", 1.0, Math.tanh(1234.56), 0D);
1121        assertEquals("Should return -1.0", -1.0, Math.tanh(-1234.56), 0D);
1122        assertEquals("Should return 9.999999999996666E-7",
1123                9.999999999996666E-7, Math.tanh(0.000001), 0D);
1124        assertEquals("Should return 0.981422884124941", 0.981422884124941, Math
1125                .tanh(2.33482), 0D);
1126        assertEquals("Should return 1.0", 1.0, Math.tanh(Double.MAX_VALUE), 0D);
1127        assertEquals("Should return 4.9E-324", 4.9E-324, Math
1128                .tanh(Double.MIN_VALUE), 0D);
1129    }
1130
1131    /**
1132     * @tests java.lang.Math#random()
1133     */
1134    @TestTargetNew(
1135        level = TestLevel.COMPLETE,
1136        notes = "",
1137        method = "random",
1138        args = {}
1139    )
1140    public void test_random() {
1141        // There isn't a place for these tests so just stick them here
1142        assertEquals("Wrong value E",
1143                4613303445314885481L, Double.doubleToLongBits(Math.E));
1144        assertEquals("Wrong value PI",
1145                4614256656552045848L, Double.doubleToLongBits(Math.PI));
1146
1147        for (int i = 500; i >= 0; i--) {
1148            double d = Math.random();
1149            assertTrue("Generated number is out of range: " + d, d >= 0.0
1150                    && d < 1.0);
1151        }
1152    }
1153
1154    /**
1155     * @tests java.lang.Math#toRadians(double)
1156     */
1157    @TestTargetNew(
1158        level = TestLevel.COMPLETE,
1159        notes = "",
1160        method = "toRadians",
1161        args = {double.class}
1162    )
1163    public void test_toRadiansD() {
1164        for (double d = 500; d >= 0; d -= 1.0) {
1165            double converted = Math.toDegrees(Math.toRadians(d));
1166            assertTrue("Converted number not equal to original. d = " + d,
1167                    converted >= d * 0.99999999 && converted <= d * 1.00000001);
1168        }
1169    }
1170
1171    /**
1172     * @tests java.lang.Math#toDegrees(double)
1173     */
1174    @TestTargetNew(
1175        level = TestLevel.COMPLETE,
1176        notes = "",
1177        method = "toDegrees",
1178        args = {double.class}
1179    )
1180    public void test_toDegreesD() {
1181        for (double d = 500; d >= 0; d -= 1.0) {
1182            double converted = Math.toRadians(Math.toDegrees(d));
1183            assertTrue("Converted number not equal to original. d = " + d,
1184                    converted >= d * 0.99999999 && converted <= d * 1.00000001);
1185        }
1186    }
1187
1188    /**
1189     * @tests java.lang.Math#ulp(double)
1190     */
1191    @TestTargetNew(
1192        level = TestLevel.COMPLETE,
1193        notes = "",
1194        method = "ulp",
1195        args = {double.class}
1196    )
1197    @SuppressWarnings("boxing")
1198    public void test_ulp_D() {
1199        // Test for special cases
1200        assertTrue("Should return NaN", Double.isNaN(Math.ulp(Double.NaN)));
1201        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
1202                .ulp(Double.POSITIVE_INFINITY), 0D);
1203        assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
1204                .ulp(Double.NEGATIVE_INFINITY), 0D);
1205        assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
1206                .ulp(0.0), 0D);
1207        assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
1208                .ulp(+0.0), 0D);
1209        assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
1210                .ulp(-0.0), 0D);
1211        assertEquals("Returned incorrect value", Math.pow(2, 971), Math
1212                .ulp(Double.MAX_VALUE), 0D);
1213        assertEquals("Returned incorrect value", Math.pow(2, 971), Math
1214                .ulp(-Double.MAX_VALUE), 0D);
1215
1216        assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
1217                .ulp(Double.MIN_VALUE), 0D);
1218        assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
1219                .ulp(-Double.MIN_VALUE), 0D);
1220
1221        assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
1222                .ulp(1.0), 0D);
1223        assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
1224                .ulp(-1.0), 0D);
1225        assertEquals("Returned incorrect value", 2.2737367544323206E-13, Math
1226                .ulp(1153.0), 0D);
1227    }
1228
1229    /**
1230     * @tests java.lang.Math#ulp(float)
1231     */
1232    @TestTargetNew(
1233        level = TestLevel.COMPLETE,
1234        notes = "",
1235        method = "ulp",
1236        args = {float.class}
1237    )
1238    @SuppressWarnings("boxing")
1239    public void test_ulp_f() {
1240        // Test for special cases
1241        assertTrue("Should return NaN", Float.isNaN(Math.ulp(Float.NaN)));
1242        assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
1243                .ulp(Float.POSITIVE_INFINITY), 0f);
1244        assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
1245                .ulp(Float.NEGATIVE_INFINITY), 0f);
1246        assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
1247                .ulp(0.0f), 0f);
1248        assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
1249                .ulp(+0.0f), 0f);
1250        assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
1251                .ulp(-0.0f), 0f);
1252        assertEquals("Returned incorrect value", 2.028241E31f, Math
1253                .ulp(Float.MAX_VALUE), 0f);
1254        assertEquals("Returned incorrect value", 2.028241E31f, Math
1255                .ulp(-Float.MAX_VALUE), 0f);
1256
1257        assertEquals("Returned incorrect value", 1.4E-45f, Math
1258                .ulp(Float.MIN_VALUE), 0f);
1259        assertEquals("Returned incorrect value", 1.4E-45f, Math
1260                .ulp(-Float.MIN_VALUE), 0f);
1261
1262        assertEquals("Returned incorrect value", 1.1920929E-7f, Math.ulp(1.0f),
1263                0f);
1264        assertEquals("Returned incorrect value", 1.1920929E-7f,
1265                Math.ulp(-1.0f), 0f);
1266        assertEquals("Returned incorrect value", 1.2207031E-4f, Math
1267                .ulp(1153.0f), 0f);
1268        assertEquals("Returned incorrect value", 5.6E-45f, Math
1269                .ulp(9.403954E-38f), 0f);
1270    }
1271}
1272