HypotTests.java revision 2362
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 809N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 809N/A * This code is free software; you can redistribute it and/or modify it 809N/A * under the terms of the GNU General Public License version 2 only, as 809N/A * published by the Free Software Foundation. 809N/A * This code is distributed in the hope that it will be useful, but WITHOUT 809N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 809N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 809N/A * version 2 for more details (a copy is included in the LICENSE file that 809N/A * accompanied this code). 809N/A * You should have received a copy of the GNU General Public License version 809N/A * 2 along with this work; if not, write to the Free Software Foundation, 809N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 809N/A * @summary Tests for {Math, StrictMath}.hypot 809N/A * @author Joseph D. Darcy 809N/A * Given integers m and n, assuming m < n, the triple (n^2 - m^2, 809N/A * 2mn, and n^2 + m^2) is a Pythagorean triple with a^2 + b^2 = 809N/A * c^2. This methods returns a long array holding the Pythagorean 809N/A * triple corresponding to the inputs. 809N/A // Verify hypot(x, 0.0) is close to x over the entire exponent 809N/A // Test Pythagorean triples 809N/A for(
int m =
1; m <
10; m++) {
809N/A for(
int n = m+
1; n <
11; n++) {
809N/A for(
int m =
100000; m <
100100; m++) {
809N/A for(
int n = m+
100000; n <
200200; n++) {
809N/A // Approaching overflow tests 809N/A * Create a random value r with an large-ish exponent. The 809N/A * result of hypot(3*r, 4*r) should be approximately 5*r. (The 809N/A * computation of 4*r is exact since it just changes the 809N/A * exponent). While the exponent of r is less than or equal 809N/A * to (MAX_EXPONENT - 3), the computation should not overflow. 809N/A for(
int i =
0; i <
1000; i++) {
809N/A // Scale d to have an exponent equal to MAX_EXPONENT -15 809N/A for(
int j =
0; j <=
13; j +=
1) {
809N/A d *=
2.0;
// increase exponent by 1 809N/A // Test for monotonicity failures. Fix one argument and test 809N/A // two numbers before and two numbers after each chosen value; 809N/A // {nextDown(nextDown(pc)), 809N/A // and we test that hypot(pcNeighbors[i]) <= hypot(pcNeighbors[i+1]) 809N/A for(
int i = -
18; i <=
18; i++) {
809N/A // Test Math and StrictMath methods with no inputs negated, 809N/A // each input negated singly, and both inputs negated. Also 809N/A // test inputs in reversed order. 809N/A for(
int i = -
1; i <=
1; i+=
2) {
809N/A for(
int j = -
1; j <=
1; j+=
2) {