equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 4851638 4939441 |
26 * @library /lib/testlibrary/ |
27 * @summary Tests for {Math, StrictMath}.hypot |
27 * @build jdk.testlibrary.* |
|
28 * @run main HypotTests |
|
29 * @bug 4851638 4939441 8078672 |
|
30 * @summary Tests for {Math, StrictMath}.hypot (use -Dseed=X to set PRNG seed) |
28 * @author Joseph D. Darcy |
31 * @author Joseph D. Darcy |
29 * @key randomness |
32 * @key randomness |
30 */ |
33 */ |
31 |
34 |
32 public class HypotTests { |
35 public class HypotTests { |
118 * result of hypot(3*r, 4*r) should be approximately 5*r. (The |
121 * result of hypot(3*r, 4*r) should be approximately 5*r. (The |
119 * computation of 4*r is exact since it just changes the |
122 * computation of 4*r is exact since it just changes the |
120 * exponent). While the exponent of r is less than or equal |
123 * exponent). While the exponent of r is less than or equal |
121 * to (MAX_EXPONENT - 3), the computation should not overflow. |
124 * to (MAX_EXPONENT - 3), the computation should not overflow. |
122 */ |
125 */ |
123 java.util.Random rand = new java.util.Random(); |
126 java.util.Random rand = RandomFactory.getRandom(); |
124 for(int i = 0; i < 1000; i++) { |
127 for(int i = 0; i < 1000; i++) { |
125 double d = rand.nextDouble(); |
128 double d = rand.nextDouble(); |
126 // Scale d to have an exponent equal to MAX_EXPONENT -15 |
129 // Scale d to have an exponent equal to MAX_EXPONENT -15 |
127 d = Math.scalb(d, Double.MAX_EXPONENT |
130 d = Math.scalb(d, Double.MAX_EXPONENT |
128 -15 - Tests.ilogb(d)); |
131 -15 - Tests.ilogb(d)); |