提交 c91b957d 编写于 作者: D darcy

6601457: Move wrapper class tests from closed to open

6601458: Move java.math tests from closed to open
6740185: Move java/lang/annotations tests to open
6759433: Move Math and StrictMath regression tests from closed to open
Summary: Move some more regression tests to the open
Reviewed-by: jjg
上级 bb15e51e
/*
* Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4262398
* @summary Basic test for Boolean.valueOf(boolean b).
*/
public class Factory {
public static void main(String[] args) throws Exception {
if (Boolean.valueOf(true) != Boolean.TRUE)
throw new Exception("Truth failure");
if (Boolean.valueOf(false) != Boolean.FALSE)
throw new Exception("Major fallacy");
}
}
/*
* Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4252308
* @summary test Boolean.getBoolean method with empty key
*/
public class GetBoolean {
public static void main(String[] args) throws Exception {
Boolean.getBoolean("");
Boolean.getBoolean(null);
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4329937
* @summary Basic test for making Boolean implement Comparable
* @author Josh Bloch
*
* @compile -source 1.5 MakeBooleanComparable.java
* @run main MakeBooleanComparable
*/
import java.util.*;
public class MakeBooleanComparable {
public static void main(String args[]) {
Random rnd = new Random();
List<Boolean> list = new ArrayList<Boolean>();
int numFalse = 0;
for (int i = 0; i < 1000; i++) {
boolean element = rnd.nextBoolean();
if (!element)
numFalse++;
list.add(element); // Autoboxing!
}
Collections.sort(list);
for (int i = 0; i < numFalse; i++)
if (list.get(i).booleanValue()) // Autounboxing doesn't work yet!
throw new RuntimeException("False positive: " + i);
for (int i = numFalse; i < 1000; i++)
if (!list.get(i).booleanValue()) // Autounboxing doesn't work yet!
throw new RuntimeException("False negative: " + i);
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4253773
* @summary test Boolean.parseBoolean
*/
public class ParseBoolean {
public static void main(String[] args) throws Exception {
checkTrue(Boolean.parseBoolean("TRUE"));
checkTrue(Boolean.parseBoolean("true"));
checkTrue(Boolean.parseBoolean("TrUe"));
checkFalse(Boolean.parseBoolean("false"));
checkFalse(Boolean.parseBoolean("FALSE"));
checkFalse(Boolean.parseBoolean("FaLse"));
checkFalse(Boolean.parseBoolean(null));
checkFalse(Boolean.parseBoolean("garbage"));
checkFalse(Boolean.parseBoolean("TRUEE"));
}
static void checkTrue(boolean b) {
if (!b)
throw new RuntimeException("test failed");
}
static void checkFalse(boolean b) {
if (b)
throw new RuntimeException("test failed");
}
}
/*
* Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4242173 5017980 6576055
* @summary Test Byte.decode method
* @author madbot
* @author Joseph D. Darcy
*/
/**
* There are six methods in java.lang.Byte which transform strings
* into a byte or Byte value:
*
* public Byte(String s)
* public static Byte decode(String nm)
* public static byte parseByte(String s, int radix)
* public static byte parseByte(String s)
* public static Byte valueOf(String s, int radix)
* public static Byte valueOf(String s)
*
* However, of these only decode has a nontrivial implementation
* in that class.
*/
public class Decode {
private static void check(String val, byte expected) {
byte n = (Byte.decode(val)).byteValue();
if (n != expected)
throw new RuntimeException("Byte.decode failed. String:" +
val + " Result:" + n);
}
private static void checkFailure(String val, String message) {
try {
byte n = (Byte.decode(val)).byteValue();
throw new RuntimeException(message);
} catch (NumberFormatException e) { /* Okay */}
}
public static void main(String[] args) throws Exception {
check(new String(""+Byte.MIN_VALUE), Byte.MIN_VALUE);
check(new String(""+Byte.MAX_VALUE), Byte.MAX_VALUE);
check("10", (byte)10);
check("0x10", (byte)16);
check("0X10", (byte)16);
check("010", (byte)8);
check("#10", (byte)16);
check("+10", (byte)10);
check("+0x10", (byte)16);
check("+0X10", (byte)16);
check("+010", (byte)8);
check("+#10", (byte)16);
check("-10", (byte)-10);
check("-0x10", (byte)-16);
check("-0X10", (byte)-16);
check("-010", (byte)-8);
check("-#10", (byte)-16);
check(Integer.toString((int)Byte.MIN_VALUE), Byte.MIN_VALUE);
check(Integer.toString((int)Byte.MAX_VALUE), Byte.MAX_VALUE);
checkFailure("0x-10", "Byte.decode allows negative sign in wrong position.");
checkFailure("0x+10", "Byte.decode allows positive sign in wrong position.");
checkFailure("+", "Raw plus sign allowed.");
checkFailure("-", "Raw minus sign allowed.");
checkFailure(Integer.toString((int)Byte.MIN_VALUE - 1), "Out of range");
checkFailure(Integer.toString((int)Byte.MAX_VALUE + 1), "Out of range");
checkFailure("", "Empty String");
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5037596
* @summary Verify bitwise conversion works for non-canonical NaN values
* @author Joseph D. Darcy
*/
import static java.lang.Double.*;
import static sun.misc.DoubleConsts.*;
public class BitwiseConversion {
static int testNanCase(long x) {
int errors = 0;
// Strip out sign and exponent bits
long y = x & SIGNIF_BIT_MASK;
double values[] = {
longBitsToDouble(EXP_BIT_MASK | y),
longBitsToDouble(SIGN_BIT_MASK | EXP_BIT_MASK | y)
};
for(double value: values) {
if (!isNaN(value)) {
throw new RuntimeException("Invalid input " + y +
"yielded non-NaN" + value);
}
long converted = doubleToLongBits(value);
if (converted != 0x7ff8000000000000L) {
errors++;
System.err.format("Non-canoncial NaN bits returned: %x%n",
converted);
}
}
return errors;
}
public static void main(String... argv) {
int errors = 0;
for (int i = 0; i < SIGNIFICAND_WIDTH-1; i++) {
errors += testNanCase(1L<<i);
}
if (doubleToLongBits(Double.POSITIVE_INFINITY)
!= 0x7ff0000000000000L) {
errors++;
System.err.println("Bad conversion for +infinity.");
}
if (doubleToLongBits(Double.NEGATIVE_INFINITY)
!= 0xfff0000000000000L) {
errors++;
System.err.println("Bad conversion for -infinity.");
}
if (errors > 0)
throw new RuntimeException();
}
}
/*
* Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @compile Constants.java
* @bug 4397405 4826652
* @summary Testing constant-ness of Double.{MIN_VALUE, MAX_VALUE}, etc.
* @author Joseph D. Darcy
*/
public class Constants {
/*
* This compile-only test is to make sure that the primitive
* public static final fields in java.lang.Double are "constant
* expressions" as defined by "The Java Language Specification,
* 2nd edition" section 15.28; a different test checks the values
* of those fields.
*/
public static void main(String[] args) throws Exception {
int i = 0;
switch (i) {
case (int)Double.NaN: // 0
System.out.println("Double.NaN is a constant!");
break;
case (int)Double.MIN_VALUE + 1: // 0 + 1
System.out.println("Double.MIN_VALUE is a constant!");
break;
case (int)Double.MIN_NORMAL + 2: // 0 + 2
System.out.println("Double.MIN_NORMAL is a constant!");
break;
case Double.MIN_EXPONENT: // -1022
System.out.println("Double.MIN_EXPONENT is a constant!");
break;
case Double.MAX_EXPONENT: // 1023
System.out.println("Double.MAX_EXPONENT is a constant!");
break;
case (int)Double.MAX_VALUE - 1: // Integer.MAX_VALUE - 1
System.out.println("Double.MAX_VALUE is a constant!");
break;
case (int)Double.POSITIVE_INFINITY: // Integer.MAX_VALUE
System.out.println("Double.POSITIVE_INFINITY is a constant!");
break;
case (int)Double.NEGATIVE_INFINITY: // Integer.MIN_VALUE
System.out.println("Double.NEGATIVE_INFINITY is a constant!");
break;
}
}
}
/*
* Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4408489 4826652
* @summary Testing values of Double.{MIN_VALUE, MIN_NORMAL, MAX_VALUE}
* @author Joseph D. Darcy
*/
public class Extrema {
public static void main(String[] args) throws Exception {
if (Double.MIN_VALUE != Double.longBitsToDouble(0x1L))
throw new RuntimeException("Double.MIN_VALUE is not equal "+
"to longBitsToDouble(0x1L).");
if (Double.MIN_NORMAL != Double.longBitsToDouble(0x0010000000000000L))
throw new RuntimeException("Double.MIN_NORMAL is not equal "+
"to longBitsToDouble(0x0010000000000000L).");
if (Double.MAX_VALUE != Double.longBitsToDouble(0x7fefffffffffffffL))
throw new RuntimeException("Double.MAX_VALUE is not equal "+
"to longBitsToDouble(0x7fefffffffffffffL).");
}
}
/*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4428772
* @summary Testing recognition of "NaN" and "Infinity" strings
* @author Joseph D. Darcy
*/
public class NaNInfinityParsing {
/*
* Regression tests for:
* 4428772 -- Establish invariant for Float & Double classes and
* their string representations
*
* Added capability for parse{Float, Double} and related methods
* to recognize "NaN" and "Infinity" strings so that
* parseDouble(toString(d)) will always return the original
* floating-point value.
*/
static String NaNStrings[] = {
"NaN",
"+NaN",
"-NaN"
};
static String infinityStrings[] = {
"Infinity",
"+Infinity",
"-Infinity",
};
static String invalidStrings[] = {
"+",
"-",
"@",
"N",
"Na",
"Nan",
"NaNf",
"NaNd",
"NaNF",
"NaND",
"+N",
"+Na",
"+Nan",
"+NaNf",
"+NaNd",
"+NaNF",
"+NaND",
"-N",
"-Na",
"-Nan",
"-NaNf",
"-NaNd",
"-NaNF",
"-NaND",
"I",
"In",
"Inf",
"Infi",
"Infin",
"Infini",
"Infinit",
"InfinitY",
"Infinityf",
"InfinityF",
"Infinityd",
"InfinityD",
"+I",
"+In",
"+Inf",
"+Infi",
"+Infin",
"+Infini",
"+Infinit",
"+InfinitY",
"+Infinityf",
"+InfinityF",
"+Infinityd",
"+InfinityD",
"-I",
"-In",
"-Inf",
"-Infi",
"-Infin",
"-Infini",
"-Infinit",
"-InfinitY",
"-Infinityf",
"-InfinityF",
"-Infinityd",
"-InfinityD",
"NaNInfinity",
"InfinityNaN",
"nan",
"infinity"
};
public static void main(String [] argv) throws Exception {
int i;
double d;
// Test valid NaN strings
for(i = 0; i < NaNStrings.length; i++) {
if(!Double.isNaN(d=Double.parseDouble(NaNStrings[i]))) {
throw new RuntimeException("NaN string ``" + NaNStrings[i]
+ "'' did not parse as a NaN; returned " +
d + " instead.");
}
}
// Test valid Infinity strings
for(i = 0; i < infinityStrings.length; i++) {
if(!Double.isInfinite(d=Double.parseDouble(infinityStrings[i]))) {
throw new RuntimeException("Infinity string ``" +
infinityStrings[i] +
"'' did not parse as infinity; returned " +
d + "instead.");
}
// check sign of result
boolean negative = (infinityStrings[i].charAt(0) == '-');
if(d != (negative?Double.NEGATIVE_INFINITY:
Double.POSITIVE_INFINITY))
throw new RuntimeException("Infinity has wrong sign;" +
(negative?"positive instead of negative.":
"negative instead of positive."));
}
// Test almost valid strings
for(i = 0; i < invalidStrings.length; i++) {
try {
double result;
d = Double.parseDouble(invalidStrings[i]);
throw new RuntimeException("Invalid string ``" +
invalidStrings[i]
+"'' parsed as " + d + ".");
}
catch(NumberFormatException e) {
// expected
}
}
}
}
/*
* Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4160406 4705734 4707389 4826774 4895911
* @summary Test for Double.parseDouble method and acceptance regex
*/
import java.util.regex.*;
public class ParseDouble {
private static void check(String val, double expected) {
double n = Double.parseDouble(val);
if (n != expected)
throw new RuntimeException("Double.parseDouble failed. String:" +
val + " Result:" + n);
}
private static void rudimentaryTest() {
check(new String(""+Double.MIN_VALUE), Double.MIN_VALUE);
check(new String(""+Double.MAX_VALUE), Double.MAX_VALUE);
check("10", (double) 10.0);
check("10.0", (double) 10.0);
check("10.01", (double) 10.01);
check("-10", (double) -10.0);
check("-10.00", (double) -10.0);
check("-10.01", (double) -10.01);
}
static String badStrings[] = {
"",
"+",
"-",
"+e",
"-e",
"+e170",
"-e170",
// Make sure intermediate white space is not deleted.
"1234 e10",
"-1234 e10",
// Control characters in the interior of a string are not legal
"1\u0007e1",
"1e\u00071",
// NaN and infinity can't have trailing type suffices or exponents
"NaNf",
"NaNF",
"NaNd",
"NaND",
"-NaNf",
"-NaNF",
"-NaNd",
"-NaND",
"+NaNf",
"+NaNF",
"+NaNd",
"+NaND",
"Infinityf",
"InfinityF",
"Infinityd",
"InfinityD",
"-Infinityf",
"-InfinityF",
"-Infinityd",
"-InfinityD",
"+Infinityf",
"+InfinityF",
"+Infinityd",
"+InfinityD",
"NaNe10",
"-NaNe10",
"+NaNe10",
"Infinitye10",
"-Infinitye10",
"+Infinitye10",
// Non-ASCII digits are not recognized
"\u0661e\u0661", // 1e1 in Arabic-Indic digits
"\u06F1e\u06F1", // 1e1 in Extended Arabic-Indic digits
"\u0967e\u0967", // 1e1 in Devanagari digits
// JCK test lex03592m3
".",
// JCK test lex03592m4
"e42",
// JCK test lex03592m5
".e42",
// JCK test lex03592m6
"d",
// JCK test lex03592m7
".d",
// JCK test lex03592m8
"e42d",
// JCK test lex03592m9
".e42d",
// JCK test lex03593m10
"1A01.01125e-10d",
// JCK test lex03593m11
"2;3.01125e-10d",
// JCK test lex03593m12
"1_34.01125e-10d",
// JCK test lex03593m14
"202..01125e-10d",
// JCK test lex03593m15
"202,01125e-10d",
// JCK test lex03593m16
"202.03b4e-10d",
// JCK test lex03593m18
"202.06_3e-10d",
// JCK test lex03593m20
"202.01125e-f0d",
// JCK test lex03593m21
"202.01125e_3d",
// JCK test lex03593m22
"202.01125e -5d",
// JCK test lex03593m24
"202.01125e-10r",
// JCK test lex03593m25
"202.01125e-10ff",
// JCK test lex03593m26
"1234L.01",
// JCK test lex03593m27
"12ee-2",
// JCK test lex03593m28
"12e-2.2.2",
// JCK test lex03593m29
"12.01e+",
// JCK test lex03593m30
"12.01E",
// Bad hexadecimal-style strings
// Two leading zeros
"00x1.0p1",
// Must have hex specifier
"1.0p1",
"00010p1",
"deadbeefp1",
// Need an explicit fully-formed exponent
"0x1.0p",
"0x1.0",
// Exponent must be in decimal
"0x1.0pa",
"0x1.0pf",
// Exponent separated by "p"
"0x1.0e22",
"0x1.0e22",
// Need a signifcand
"0xp22"
};
static String goodStrings[] = {
"NaN",
"+NaN",
"-NaN",
"Infinity",
"+Infinity",
"-Infinity",
"1.1e-23f",
".1e-23f",
"1e-23",
"1f",
"0",
"-0",
"+0",
"00",
"00",
"-00",
"+00",
"0000000000",
"-0000000000",
"+0000000000",
"1",
"2",
"1234",
"-1234",
"+1234",
"2147483647", // Integer.MAX_VALUE
"2147483648",
"-2147483648", // Integer.MIN_VALUE
"-2147483649",
"16777215",
"16777216", // 2^24
"16777217",
"-16777215",
"-16777216", // -2^24
"-16777217",
"9007199254740991",
"9007199254740992", // 2^53
"9007199254740993",
"-9007199254740991",
"-9007199254740992", // -2^53
"-9007199254740993",
"9223372036854775807",
"9223372036854775808", // Long.MAX_VALUE
"9223372036854775809",
"-9223372036854775808",
"-9223372036854775809", // Long.MIN_VALUE
"-9223372036854775810",
// Culled from JCK test lex03591m1
"54.07140d",
"7.01e-324d",
"2147483647.01d",
"1.2147483647f",
"000000000000000000000000001.F",
"1.00000000000000000000000000e-2F",
// Culled from JCK test lex03592m2
"2.",
".0909",
"122112217090.0",
"7090e-5",
"2.E-20",
".0909e42",
"122112217090.0E+100",
"7090f",
"2.F",
".0909d",
"122112217090.0D",
"7090e-5f",
"2.E-20F",
".0909e42d",
"122112217090.0E+100D",
// Culled from JCK test lex03594m31 -- unicode escapes
"\u0035\u0031\u0034\u0039\u0032\u0033\u0036\u0037\u0038\u0030.1102E-209D",
"1290873\u002E12301e100",
"1.1E-10\u0066",
// Culled from JCK test lex03595m1
"0.0E-10",
"1E10",
// Culled from JCK test lex03691m1
"0.f",
"1f",
"0.F",
"1F",
"0.12d",
"1e-0d",
"12.e+1D",
"0e-0D",
"12.e+01",
"1e-01",
// Good hex strings
// Vary capitalization of separators.
"0x1p1",
"0X1p1",
"0x1P1",
"0X1P1",
"0x1p1f",
"0X1p1f",
"0x1P1f",
"0X1P1f",
"0x1p1F",
"0X1p1F",
"0x1P1F",
"0X1P1F",
"0x1p1d",
"0X1p1d",
"0x1P1d",
"0X1P1d",
"0x1p1D",
"0X1p1D",
"0x1P1D",
"0X1P1D",
"-0x1p1",
"-0X1p1",
"-0x1P1",
"-0X1P1",
"-0x1p1f",
"-0X1p1f",
"-0x1P1f",
"-0X1P1f",
"-0x1p1F",
"-0X1p1F",
"-0x1P1F",
"-0X1P1F",
"-0x1p1d",
"-0X1p1d",
"-0x1P1d",
"-0X1P1d",
"-0x1p1D",
"-0X1p1D",
"-0x1P1D",
"-0X1P1D",
"0x1p-1",
"0X1p-1",
"0x1P-1",
"0X1P-1",
"0x1p-1f",
"0X1p-1f",
"0x1P-1f",
"0X1P-1f",
"0x1p-1F",
"0X1p-1F",
"0x1P-1F",
"0X1P-1F",
"0x1p-1d",
"0X1p-1d",
"0x1P-1d",
"0X1P-1d",
"0x1p-1D",
"0X1p-1D",
"0x1P-1D",
"0X1P-1D",
"-0x1p-1",
"-0X1p-1",
"-0x1P-1",
"-0X1P-1",
"-0x1p-1f",
"-0X1p-1f",
"-0x1P-1f",
"-0X1P-1f",
"-0x1p-1F",
"-0X1p-1F",
"-0x1P-1F",
"-0X1P-1F",
"-0x1p-1d",
"-0X1p-1d",
"-0x1P-1d",
"-0X1P-1d",
"-0x1p-1D",
"-0X1p-1D",
"-0x1P-1D",
"-0X1P-1D",
// Try different significand combinations
"0xap1",
"0xbp1",
"0xcp1",
"0xdp1",
"0xep1",
"0xfp1",
"0x1p1",
"0x.1p1",
"0x1.1p1",
"0x001p23",
"0x00.1p1",
"0x001.1p1",
"0x100p1",
"0x.100p1",
"0x1.100p1",
"0x00100p1",
"0x00.100p1",
"0x001.100p1"
};
static String paddedBadStrings[];
static String paddedGoodStrings[];
static {
String pad = " \t\n\r\f\u0001\u000b\u001f";
paddedBadStrings = new String[badStrings.length];
for(int i = 0 ; i < badStrings.length; i++)
paddedBadStrings[i] = pad + badStrings[i] + pad;
paddedGoodStrings = new String[goodStrings.length];
for(int i = 0 ; i < goodStrings.length; i++)
paddedGoodStrings[i] = pad + goodStrings[i] + pad;
}
/*
* Throws an exception if <code>Input</code> is
* <code>exceptionalInput</code> and {@link Double.parseDouble
* parseDouble} does <em>not</em> throw an exception or if
* <code>Input</code> is not <code>exceptionalInput</code> and
* <code>parseDouble</code> throws an exception. This method does
* not attempt to test whether the string is converted to the
* proper value; just whether the input is accepted appropriately
* or not.
*/
private static void testParsing(String [] input,
boolean exceptionalInput) {
for(int i = 0; i < input.length; i++) {
double d;
try {
d = Double.parseDouble(input[i]);
}
catch (NumberFormatException e) {
if (! exceptionalInput) {
throw new RuntimeException("Double.parseDouble rejected " +
"good string `" + input[i] +
"'.");
}
break;
}
if (exceptionalInput) {
throw new RuntimeException("Double.parseDouble accepted " +
"bad string `" + input[i] +
"'.");
}
}
}
/*
* Throws an exception if <code>Input</code> is
* <code>exceptionalInput</code> and the regular expression
* matches one of the strings or if <code>Input</code> is not
* <code>exceptionalInput</code> and the regular expression fails
* to match an input string.
*/
private static void testRegex(String [] input, boolean exceptionalInput) {
/*
* The regex below is taken from the JavaDoc for
* Double.valueOf.
*/
final String Digits = "(\\p{Digit}+)";
final String HexDigits = "(\\p{XDigit}+)";
// an exponent is 'e' or 'E' followed by an optionally
// signed decimal integer.
final String Exp = "[eE][+-]?"+Digits;
final String fpRegex =
("[\\x00-\\x20]*"+ // Optional leading "whitespace"
"[+-]?(" + // Optional sign character
"NaN|" + // "NaN" string
"Infinity|" + // "Infinity" string
// A floating-point string representing a finite positive
// number without a leading sign has at most five basic pieces:
// Digits . Digits ExponentPart FloatTypeSuffix
//
// Since this method allows integer-only strings as input
// in addition to strings of floating-point literals, the
// two sub-patterns below are simplifications of the grammar
// productions from the Java Language Specification, 2nd
// edition, section 3.10.2.
// A decimal floating-point string representing a finite positive
// number without a leading sign has at most five basic pieces:
// Digits . Digits ExponentPart FloatTypeSuffix
//
// Since this method allows integer-only strings as input
// in addition to strings of floating-point literals, the
// two sub-patterns below are simplifications of the grammar
// productions from the Java Language Specification, 2nd
// edition, section 3.10.2.
// Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt
"(((("+Digits+"(\\.)?("+Digits+"?)("+Exp+")?)|"+
// . Digits ExponentPart_opt FloatTypeSuffix_opt
"(\\.("+Digits+")("+Exp+")?))|"+
// Hexadecimal strings
"((" +
// 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt
"(0[xX]" + HexDigits + "(\\.)?)|" +
// 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt
"(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" +
")[pP][+-]?" + Digits + "))" +
"[fFdD]?))" +
"[\\x00-\\x20]*");// Optional trailing "whitespace"
Pattern fpPattern = Pattern.compile(fpRegex);
for(int i = 0; i < input.length; i++) {
Matcher m = fpPattern.matcher(input[i]);
if (m.matches() != ! exceptionalInput) {
throw new RuntimeException("Regular expression " +
(exceptionalInput?
"accepted bad":
"rejected good") +
" string `" +
input[i] + "'.");
}
}
}
public static void main(String[] args) throws Exception {
rudimentaryTest();
testParsing(goodStrings, false);
testParsing(paddedGoodStrings, false);
testParsing(badStrings, true);
testParsing(paddedBadStrings, true);
testRegex(goodStrings, false);
testRegex(paddedGoodStrings, false);
testRegex(badStrings, true);
testRegex(paddedBadStrings, true);
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4826774
* @summary Numerical tests for hexadecimal inputs to parseDouble, parseFloat
* @author Joseph D. Darcy
*/
import java.util.regex.*;
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class ParseHexFloatingPoint {
private ParseHexFloatingPoint(){}
public static final double infinityD = Double.POSITIVE_INFINITY;
public static final double NaND = Double.NaN;
static int test(String testName, String input,
double result, double expected) {
int failures =0;
if (Double.compare(result, expected) != 0 ) {
System.err.println("Failure for " + testName +
": For input " + input +
" expected " + expected +
" got " + result + ".");
}
return failures;
}
static int testCase(String input, double expected) {
int failures =0;
// Try different combination of letter components
input = input.toLowerCase(java.util.Locale.US);
String [] suffices = {"", "f", "F", "d", "D"};
String [] signs = {"", "-", "+"};
for(int i = 0; i < 2; i++) {
String s1 = input;
if(i == 1)
s1 = s1.replace('x', 'X');
for(int j = 0; j < 2; j++) {
String s2 = s1;
if(j == 1)
s2 = s2.replace('p', 'P');
for(int k = 0; k < 2; k++) {
String s3 = s2;
if(k == 1)
s3 = upperCaseHex(s3);
for(int m = 0; m < suffices.length; m++) {
String s4 = s3 + suffices[m];
for(int n = 0; n < signs.length; n++) {
String s5 = signs[n] + s4;
double result = Double.parseDouble(s5);
failures += test("Double.parseDouble",
s5, result, (signs[n].equals("-") ?
-expected:
expected));
}
}
}
}
}
return failures;
}
static String upperCaseHex(String s) {
return s.replace('a', 'A').replace('b', 'B').replace('c', 'C').
replace('d', 'D').replace('e','E').replace('f', 'F');
}
/*
* Test easy and tricky double rounding cases.
*/
static int doubleTests() {
/*
* A String, double pair
*/
class PairSD {
public String s;
public double d;
PairSD(String s, double d) {
this.s = s;
this.d = d;
}
}
int failures = 0;
// Hex strings that convert to three; test basic functionality
// of significand and exponent shift adjusts along with the
// no-op of adding leading zeros. These cases don't exercise
// the rounding code.
String leadingZeros = "0x0000000000000000000";
String [] threeTests = {
"0x.003p12",
"0x.006p11",
"0x.00cp10",
"0x.018p9",
"0x.3p4",
"0x.6p3",
"0x.cp2",
"0x1.8p1",
"0x3p0",
"0x6.0p-1",
"0xc.0p-2",
"0x18.0p-3",
"0x3000000p-24",
"0x3.0p0",
"0x3.000000p0",
};
for(int i=0; i < threeTests.length; i++) {
String input = threeTests[i];
failures += testCase(input, 3.0);
input.replaceFirst("^0x", leadingZeros);
failures += testCase(input, 3.0);
}
long bigExponents [] = {
2*DoubleConsts.MAX_EXPONENT,
2*DoubleConsts.MIN_EXPONENT,
(long)Integer.MAX_VALUE-1,
(long)Integer.MAX_VALUE,
(long)Integer.MAX_VALUE+1,
(long)Integer.MIN_VALUE-1,
(long)Integer.MIN_VALUE,
(long)Integer.MIN_VALUE+1,
Long.MAX_VALUE-1,
Long.MAX_VALUE,
Long.MIN_VALUE+1,
Long.MIN_VALUE,
};
// Test zero significand with large exponents.
for(int i = 0; i < bigExponents.length; i++) {
failures += testCase("0x0.0p"+Long.toString(bigExponents[i]) , 0.0);
}
// Test nonzero significand with large exponents.
for(int i = 0; i < bigExponents.length; i++) {
long exponent = bigExponents[i];
failures += testCase("0x10000.0p"+Long.toString(exponent) ,
(exponent <0?0.0:infinityD));
}
// Test significands with different lengths and bit patterns.
{
long signif = 0;
for(int i = 1; i <= 0xe; i++) {
signif = (signif <<4) | (long)i;
failures += testCase("0x"+Long.toHexString(signif)+"p0", signif);
}
}
PairSD [] testCases = {
new PairSD("0x0.0p0", 0.0/16.0),
new PairSD("0x0.1p0", 1.0/16.0),
new PairSD("0x0.2p0", 2.0/16.0),
new PairSD("0x0.3p0", 3.0/16.0),
new PairSD("0x0.4p0", 4.0/16.0),
new PairSD("0x0.5p0", 5.0/16.0),
new PairSD("0x0.6p0", 6.0/16.0),
new PairSD("0x0.7p0", 7.0/16.0),
new PairSD("0x0.8p0", 8.0/16.0),
new PairSD("0x0.9p0", 9.0/16.0),
new PairSD("0x0.ap0", 10.0/16.0),
new PairSD("0x0.bp0", 11.0/16.0),
new PairSD("0x0.cp0", 12.0/16.0),
new PairSD("0x0.dp0", 13.0/16.0),
new PairSD("0x0.ep0", 14.0/16.0),
new PairSD("0x0.fp0", 15.0/16.0),
// Half-way case between zero and MIN_VALUE rounds down to
// zero
new PairSD("0x1.0p-1075", 0.0),
// Slighly more than half-way case between zero and
// MIN_VALUES rounds up to zero.
new PairSD("0x1.1p-1075", Double.MIN_VALUE),
new PairSD("0x1.000000000001p-1075", Double.MIN_VALUE),
new PairSD("0x1.000000000000001p-1075", Double.MIN_VALUE),
// More subnormal rounding tests
new PairSD("0x0.fffffffffffff7fffffp-1022", FpUtils.nextDown(DoubleConsts.MIN_NORMAL)),
new PairSD("0x0.fffffffffffff8p-1022", DoubleConsts.MIN_NORMAL),
new PairSD("0x0.fffffffffffff800000001p-1022",DoubleConsts.MIN_NORMAL),
new PairSD("0x0.fffffffffffff80000000000000001p-1022",DoubleConsts.MIN_NORMAL),
new PairSD("0x1.0p-1022", DoubleConsts.MIN_NORMAL),
// Large value and overflow rounding tests
new PairSD("0x1.fffffffffffffp1023", Double.MAX_VALUE),
new PairSD("0x1.fffffffffffff0000000p1023", Double.MAX_VALUE),
new PairSD("0x1.fffffffffffff4p1023", Double.MAX_VALUE),
new PairSD("0x1.fffffffffffff7fffffp1023", Double.MAX_VALUE),
new PairSD("0x1.fffffffffffff8p1023", infinityD),
new PairSD("0x1.fffffffffffff8000001p1023", infinityD),
new PairSD("0x1.ffffffffffffep1023", FpUtils.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe0000p1023", FpUtils.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe8p1023", FpUtils.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffe7p1023", FpUtils.nextDown(Double.MAX_VALUE)),
new PairSD("0x1.ffffffffffffeffffffp1023", Double.MAX_VALUE),
new PairSD("0x1.ffffffffffffe8000001p1023", Double.MAX_VALUE),
};
for (int i = 0; i < testCases.length; i++) {
failures += testCase(testCases[i].s,testCases[i].d);
}
failures += significandAlignmentTests();
{
java.util.Random rand = new java.util.Random();
// Consistency check; double => hexadecimal => double
// preserves the original value.
for(int i = 0; i < 1000; i++) {
double d = rand.nextDouble();
failures += testCase(Double.toHexString(d), d);
}
}
return failures;
}
/*
* Verify rounding works the same regardless of how the
* significand is aligned on input. A useful extension could be
* to have this sort of test for strings near the overflow
* threshold.
*/
static int significandAlignmentTests() {
int failures = 0;
// baseSignif * 2^baseExp = nextDown(2.0)
long [] baseSignifs = {
0x1ffffffffffffe00L,
0x1fffffffffffff00L
};
double [] answers = {
FpUtils.nextDown(FpUtils.nextDown(2.0)),
FpUtils.nextDown(2.0),
2.0
};
int baseExp = -60;
int count = 0;
for(int i = 0; i < 2; i++) {
for(long j = 0; j <= 0xfL; j++) {
for(long k = 0; k <= 8; k+= 4) { // k = {0, 4, 8}
long base = baseSignifs[i];
long testValue = base | (j<<4) | k;
int offset = 0;
// Calculate when significand should be incremented
// see table 4.7 in Koren book
if ((base & 0x100L) == 0L ) { // lsb is 0
if ( (j >= 8L) && // round is 1
((j & 0x7L) != 0 || k != 0 ) ) // sticky is 1
offset = 1;
}
else { // lsb is 1
if (j >= 8L) // round is 1
offset = 1;
}
double expected = answers[i+offset];
for(int m = -2; m <= 3; m++) {
count ++;
// Form equal value string and evaluate it
String s = "0x" +
Long.toHexString((m >=0) ?(testValue<<m):(testValue>>(-m))) +
"p" + (baseExp - m);
failures += testCase(s, expected);
}
}
}
}
return failures;
}
/*
* Test tricky float rounding cases. The code which
* reads in a hex string converts the string to a double value.
* If a float value is needed, the double value is cast to float.
* However, the cast be itself not always guaranteed to return the
* right result since:
*
* 1. hex string => double can discard a sticky bit which would
* influence a direct hex string => float conversion.
*
* 2. hex string => double => float can have a rounding to double
* precision which results in a larger float value while a direct
* hex string => float conversion would not round up.
*
* This method includes tests of the latter two possibilities.
*/
static int floatTests(){
int failures = 0;
/*
* A String, float pair
*/
class PairSD {
public String s;
public float f;
PairSD(String s, float f) {
this.s = s;
this.f = f;
}
}
String [][] roundingTestCases = {
// Target float value hard rouding version
{"0x1.000000p0", "0x1.0000000000001p0"},
// Try some values that should round up to nextUp(1.0f)
{"0x1.000002p0", "0x1.0000010000001p0"},
{"0x1.000002p0", "0x1.00000100000008p0"},
{"0x1.000002p0", "0x1.0000010000000fp0"},
{"0x1.000002p0", "0x1.00000100000001p0"},
{"0x1.000002p0", "0x1.00000100000000000000000000000000000000001p0"},
{"0x1.000002p0", "0x1.0000010000000fp0"},
// Potential double rounding cases
{"0x1.000002p0", "0x1.000002fffffffp0"},
{"0x1.000002p0", "0x1.000002fffffff8p0"},
{"0x1.000002p0", "0x1.000002ffffffffp0"},
{"0x1.000002p0", "0x1.000002ffff0ffp0"},
{"0x1.000002p0", "0x1.000002ffff0ff8p0"},
{"0x1.000002p0", "0x1.000002ffff0fffp0"},
{"0x1.000000p0", "0x1.000000fffffffp0"},
{"0x1.000000p0", "0x1.000000fffffff8p0"},
{"0x1.000000p0", "0x1.000000ffffffffp0"},
{"0x1.000000p0", "0x1.000000ffffffep0"},
{"0x1.000000p0", "0x1.000000ffffffe8p0"},
{"0x1.000000p0", "0x1.000000ffffffefp0"},
// Float subnormal cases
{"0x0.000002p-126", "0x0.0000010000001p-126"},
{"0x0.000002p-126", "0x0.00000100000000000001p-126"},
{"0x0.000006p-126", "0x0.0000050000001p-126"},
{"0x0.000006p-126", "0x0.00000500000000000001p-126"},
{"0x0.0p-149", "0x0.7ffffffffffffffp-149"},
{"0x1.0p-148", "0x1.3ffffffffffffffp-148"},
{"0x1.cp-147", "0x1.bffffffffffffffp-147"},
{"0x1.fffffcp-127", "0x1.fffffdffffffffp-127"},
};
String [] signs = {"", "-"};
for(int i = 0; i < roundingTestCases.length; i++) {
for(int j = 0; j < signs.length; j++) {
String expectedIn = signs[j]+roundingTestCases[i][0];
String resultIn = signs[j]+roundingTestCases[i][1];
float expected = Float.parseFloat(expectedIn);
float result = Float.parseFloat(resultIn);
if( Float.compare(expected, result) != 0) {
failures += 1;
System.err.println("" + (i+1));
System.err.println("Expected = " + Float.toHexString(expected));
System.err.println("Rounded = " + Float.toHexString(result));
System.err.println("Double = " + Double.toHexString(Double.parseDouble(resultIn)));
System.err.println("Input = " + resultIn);
System.err.println("");
}
}
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += doubleTests();
failures += floatTests();
if (failures != 0) {
throw new RuntimeException("" + failures + " failures while " +
"testing hexadecimal floating-point " +
"parsing.");
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4826774 4926547
* @summary Tests for {Float, Double}.toHexString methods
* @author Joseph D. Darcy
*/
import java.util.regex.*;
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class ToHexString {
private ToHexString() {}
/*
* Given a double value, create a hexadecimal floating-point
* string via an intermediate long hex string.
*/
static String doubleToHexString(double d) {
return hexLongStringtoHexDoubleString(Long.toHexString(Double.doubleToLongBits(d)));
}
/*
* Transform the hexadecimal long output into the equivalent
* hexadecimal double value.
*/
static String hexLongStringtoHexDoubleString(String transString) {
transString = transString.toLowerCase();
String zeros = "";
StringBuffer result = new StringBuffer(24);
for(int i = 0; i < (16 - transString.length()); i++, zeros += "0");
transString = zeros + transString;
// assert transString.length == 16;
char topChar;
// Extract sign
if((topChar=transString.charAt(0)) >= '8' ) {// 8, 9, a, A, b, B, ...
result.append("-");
// clear sign bit
transString =
Character.toString(Character.forDigit(Character.digit(topChar, 16) - 8, 16)) +
transString.substring(1,16);
}
// check for NaN and infinity
String signifString = transString.substring(3,16);
if( transString.substring(0,3).equals("7ff") ) {
if(signifString.equals("0000000000000")) {
result.append("Infinity");
}
else
result.append("NaN");
}
else { // finite value
// Extract exponent
int exponent = Integer.parseInt(transString.substring(0,3), 16) -
DoubleConsts.EXP_BIAS;
result.append("0x");
if (exponent == DoubleConsts.MIN_EXPONENT - 1) { // zero or subnormal
if(signifString.equals("0000000000000")) {
result.append("0.0p0");
}
else {
result.append("0." + signifString.replaceFirst("0+$", "").replaceFirst("^$", "0") +
"p-1022");
}
}
else { // normal value
result.append("1." + signifString.replaceFirst("0+$", "").replaceFirst("^$", "0") +
"p" + exponent);
}
}
return result.toString();
}
public static int toHexStringTests() {
int failures = 0;
String [][] testCases1 = {
{"Infinity", "Infinity"},
{"-Infinity", "-Infinity"},
{"NaN", "NaN"},
{"-NaN", "NaN"},
{"0.0", "0x0.0p0"},
{"-0.0", "-0x0.0p0"},
{"1.0", "0x1.0p0"},
{"-1.0", "-0x1.0p0"},
{"2.0", "0x1.0p1"},
{"3.0", "0x1.8p1"},
{"0.5", "0x1.0p-1"},
{"0.25", "0x1.0p-2"},
{"1.7976931348623157e+308", "0x1.fffffffffffffp1023"}, // MAX_VALUE
{"2.2250738585072014E-308", "0x1.0p-1022"}, // MIN_NORMAL
{"2.225073858507201E-308", "0x0.fffffffffffffp-1022"}, // MAX_SUBNORMAL
{"4.9e-324", "0x0.0000000000001p-1022"} // MIN_VALUE
};
// Compare decimal string -> double -> hex string to hex string
for (int i = 0; i < testCases1.length; i++) {
String result;
if(! (result=Double.toHexString(Double.parseDouble(testCases1[i][0]))).
equals(testCases1[i][1])) {
failures ++;
System.err.println("For floating-point string " + testCases1[i][0] +
", expected hex output " + testCases1[i][1] + ", got " + result +".");
}
}
// Except for float subnormals, the output for numerically
// equal float and double values should be the same.
// Therefore, we will explicitly test float subnormal values.
String [][] floatTestCases = {
{"Infinity", "Infinity"},
{"-Infinity", "-Infinity"},
{"NaN", "NaN"},
{"-NaN", "NaN"},
{"0.0", "0x0.0p0"},
{"-0.0", "-0x0.0p0"},
{"1.0", "0x1.0p0"},
{"-1.0", "-0x1.0p0"},
{"2.0", "0x1.0p1"},
{"3.0", "0x1.8p1"},
{"0.5", "0x1.0p-1"},
{"0.25", "0x1.0p-2"},
{"3.4028235e+38f", "0x1.fffffep127"}, // MAX_VALUE
{"1.17549435E-38f", "0x1.0p-126"}, // MIN_NORMAL
{"1.1754942E-38", "0x0.fffffep-126"}, // MAX_SUBNORMAL
{"1.4e-45f", "0x0.000002p-126"} // MIN_VALUE
};
// Compare decimal string -> double -> hex string to hex string
for (int i = 0; i < floatTestCases.length; i++) {
String result;
if(! (result=Float.toHexString(Float.parseFloat(floatTestCases[i][0]))).
equals(floatTestCases[i][1])) {
failures++;
System.err.println("For floating-point string " + floatTestCases[i][0] +
", expected hex output\n" + floatTestCases[i][1] + ", got\n" + result +".");
}
}
// Particular floating-point values and hex equivalents, mostly
// taken from fdlibm source.
String [][] testCases2 = {
{"+0.0", "0000000000000000"},
{"-0.0", "8000000000000000"},
{"+4.9e-324", "0000000000000001"},
{"-4.9e-324", "8000000000000001"},
// fdlibm k_sin.c
{"+5.00000000000000000000e-01", "3FE0000000000000"},
{"-1.66666666666666324348e-01", "BFC5555555555549"},
{"+8.33333333332248946124e-03", "3F8111111110F8A6"},
{"-1.98412698298579493134e-04", "BF2A01A019C161D5"},
{"+2.75573137070700676789e-06", "3EC71DE357B1FE7D"},
{"-2.50507602534068634195e-08", "BE5AE5E68A2B9CEB"},
{"+1.58969099521155010221e-10", "3DE5D93A5ACFD57C"},
// fdlibm k_cos.c
{"+4.16666666666666019037e-02", "3FA555555555554C"},
{"-1.38888888888741095749e-03", "BF56C16C16C15177"},
{"+2.48015872894767294178e-05", "3EFA01A019CB1590"},
{"-2.75573143513906633035e-07", "BE927E4F809C52AD"},
{"+2.08757232129817482790e-09", "3E21EE9EBDB4B1C4"},
{"-1.13596475577881948265e-11", "BDA8FAE9BE8838D4"},
// fdlibm e_rempio.c
{"1.67772160000000000000e+07", "4170000000000000"},
{"6.36619772367581382433e-01", "3FE45F306DC9C883"},
{"1.57079632673412561417e+00", "3FF921FB54400000"},
{"6.07710050650619224932e-11", "3DD0B4611A626331"},
{"6.07710050630396597660e-11", "3DD0B4611A600000"},
{"2.02226624879595063154e-21", "3BA3198A2E037073"},
{"2.02226624871116645580e-21", "3BA3198A2E000000"},
{"8.47842766036889956997e-32", "397B839A252049C1"},
// fdlibm s_cbrt.c
{"+5.42857142857142815906e-01", "3FE15F15F15F15F1"},
{"-7.05306122448979611050e-01", "BFE691DE2532C834"},
{"+1.41428571428571436819e+00", "3FF6A0EA0EA0EA0F"},
{"+1.60714285714285720630e+00", "3FF9B6DB6DB6DB6E"},
{"+3.57142857142857150787e-01", "3FD6DB6DB6DB6DB7"},
};
// Compare decimal string -> double -> hex string to
// long hex string -> double hex string
for (int i = 0; i < testCases2.length; i++) {
String result;
String expected;
if(! (result=Double.toHexString(Double.parseDouble(testCases2[i][0]))).
equals( expected=hexLongStringtoHexDoubleString(testCases2[i][1]) )) {
failures ++;
System.err.println("For floating-point string " + testCases2[i][0] +
", expected hex output " + expected + ", got " + result +".");
}
}
// Test random double values;
// compare double -> Double.toHexString with local doubleToHexString
java.util.Random rand = new java.util.Random(0);
for (int i = 0; i < 1000; i++) {
String result;
String expected;
double d = rand.nextDouble();
if(! (expected=doubleToHexString(d)).equals(result=Double.toHexString(d)) ) {
failures ++;
System.err.println("For floating-point value " + d +
", expected hex output " + expected + ", got " + result +".");
}
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures = toHexStringTests();
if (failures != 0) {
throw new RuntimeException("" + failures + " failures while testing Double.toHexString");
}
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5037596
* @summary Verify bitwise conversion works for non-canonical NaN values
* @author Joseph D. Darcy
*/
import static java.lang.Float.*;
import static sun.misc.FloatConsts.*;
public class BitwiseConversion {
static int testNanCase(int x) {
int errors = 0;
// Strip out sign and exponent bits
int y = x & SIGNIF_BIT_MASK;
float values[] = {
intBitsToFloat(EXP_BIT_MASK | y),
intBitsToFloat(SIGN_BIT_MASK | EXP_BIT_MASK | y)
};
for(float value: values) {
if (!isNaN(value)) {
throw new RuntimeException("Invalid input " + y +
"yielded non-NaN" + value);
}
int converted = floatToIntBits(value);
if (converted != 0x7fc00000) {
errors++;
System.err.format("Non-canoncial NaN bits returned: %x%n",
converted);
}
}
return errors;
}
public static void main(String... argv) {
int errors = 0;
for (int i = 0; i < SIGNIFICAND_WIDTH-1; i++) {
errors += testNanCase(1<<i);
}
if (floatToIntBits(Float.POSITIVE_INFINITY)
!= 0x7F800000) {
errors++;
System.err.println("Bad conversion for +infinity.");
}
if (floatToIntBits(Float.NEGATIVE_INFINITY)
!= 0xFF800000) {
errors++;
System.err.println("Bad conversion for -infinity.");
}
if (errors > 0)
throw new RuntimeException();
}
}
/*
* Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @compile Constants.java
* @bug 4397405 4826652
* @summary Testing constant-ness of Float.{MIN_VALUE, MAX_VALUE}, etc.
* @author Joseph D. Darcy
*/
public class Constants {
/*
* This compile-only test is to make sure that the primitive
* public static final fields in java.lang.Float are "constant
* expressions" as defined by "The Java Language Specification,
* 2nd edition" section 15.28; a different test checks the values
* of those fields.
*/
public static void main(String[] args) throws Exception {
int i = 0;
switch (i) {
case (int)Float.NaN: // 0
System.out.println("Float.NaN is a constant!");
break;
case (int)Float.MIN_VALUE + 1: // 0 + 1
System.out.println("Float.MIN_VALUE is a constant!");
break;
case (int)Float.MIN_NORMAL + 2: // 0 + 2
System.out.println("Float.MIN_NORMAL is a constant!");
break;
case Float.MIN_EXPONENT: // -126
System.out.println("Float.MIN_EXPONENT is a constant!");
break;
case Float.MAX_EXPONENT: // 127
System.out.println("Float.MAX_EXPONENT is a constant!");
break;
case (int)Float.MAX_VALUE - 1: // Integer.MAX_VALUE - 1
System.out.println("Float.MAX_VALUE is a constant!");
break;
case (int)Float.POSITIVE_INFINITY: // Integer.MAX_VALUE
System.out.println("Float.POSITIVE_INFINITY is a constant!");
break;
case (int)Float.NEGATIVE_INFINITY: // Integer.MIN_VALUE
System.out.println("Float.NEGATIVE_INFINITY is a constant!");
break;
}
}
}
/*
* Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4408489 4826652
* @summary Testing values of Float.{MIN_VALUE, MIN_NORMAL, MAX_VALUE}
* @author Joseph D. Darcy
*/
public class Extrema {
public static void main(String[] args) throws Exception {
if (Float.MIN_VALUE != Float.intBitsToFloat(0x1))
throw new RuntimeException("Float.MIN_VALUE is not equal "+
"to intBitsToFloat(0x1).");
if (Float.MIN_NORMAL != Float.intBitsToFloat(0x00800000))
throw new RuntimeException("Float.MIN_NORMAL is not equal "+
"to intBitsToFloat(0x00800000).");
if (Float.MAX_VALUE != Float.intBitsToFloat(0x7f7fffff))
throw new RuntimeException("Float.MAX_VALUE is not equal "+
"to intBitsToFloat(0x7f7fffff).");
}
}
/*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4428772
* @summary Testing recognition of "NaN" and "Infinity" strings
* @author Joseph D. Darcy
*/
public class NaNInfinityParsing {
/*
* Regression tests for:
* 4428772 -- Establish invariant for Float & Double classes and
* their string representations
*
* Added capability for parse{Float, Double} and related methods
* to recognize "NaN" and "Infinity" strings so that
* parseFloat(toString(d)) will always return the original
* floating-point value.
*/
static String NaNStrings[] = {
"NaN",
"+NaN",
"-NaN"
};
static String infinityStrings[] = {
"Infinity",
"+Infinity",
"-Infinity",
};
static String invalidStrings[] = {
"+",
"-",
"@",
"N",
"Na",
"Nan",
"NaNf",
"NaNd",
"NaNF",
"NaND",
"+N",
"+Na",
"+Nan",
"+NaNf",
"+NaNd",
"+NaNF",
"+NaND",
"-N",
"-Na",
"-Nan",
"-NaNf",
"-NaNd",
"-NaNF",
"-NaND",
"I",
"In",
"Inf",
"Infi",
"Infin",
"Infini",
"Infinit",
"InfinitY",
"Infinityf",
"InfinityF",
"Infinityd",
"InfinityD",
"+I",
"+In",
"+Inf",
"+Infi",
"+Infin",
"+Infini",
"+Infinit",
"+InfinitY",
"+Infinityf",
"+InfinityF",
"+Infinityd",
"+InfinityD",
"-I",
"-In",
"-Inf",
"-Infi",
"-Infin",
"-Infini",
"-Infinit",
"-InfinitY",
"-Infinityf",
"-InfinityF",
"-Infinityd",
"-InfinityD",
"NaNInfinity",
"InfinityNaN",
"nan",
"infinity"
};
public static void main(String [] argv) throws Exception {
int i;
float d;
// Test valid NaN strings
for(i = 0; i < NaNStrings.length; i++) {
if(!Float.isNaN(d=Float.parseFloat(NaNStrings[i]))) {
throw new RuntimeException("NaN string ``" + NaNStrings[i]
+ "'' did not parse as a NaN; returned " +
d + " instead.");
}
}
// Test valid Infinity strings
for(i = 0; i < infinityStrings.length; i++) {
if(!Float.isInfinite(d=Float.parseFloat(infinityStrings[i]))) {
throw new RuntimeException("Infinity string ``" +
infinityStrings[i] +
"'' did not parse as infinity; returned " +
d + "instead.");
}
// check sign of result
boolean negative = (infinityStrings[i].charAt(0) == '-');
if(d != (negative?Float.NEGATIVE_INFINITY:
Float.POSITIVE_INFINITY))
throw new RuntimeException("Infinity has wrong sign;" +
(negative?"positive instead of negative.":
"negative instead of positive."));
}
// Test almost valid strings
for(i = 0; i < invalidStrings.length; i++) {
try {
float result;
d = Float.parseFloat(invalidStrings[i]);
throw new RuntimeException("Invalid string ``" +
invalidStrings[i]
+"'' parsed as " + d + ".");
}
catch(NumberFormatException e) {
// expected
}
}
}
}
/*
* Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4160406 4705734 4707389
* @summary Tests for Float.parseFloat method
*/
public class ParseFloat {
private static void check(String val, float expected) {
float n = Float.parseFloat(val);
if (n != expected)
throw new RuntimeException("Float.parseFloat failed. String:" +
val + " Result:" + n);
}
private static void rudimentaryTest() {
check(new String(""+Float.MIN_VALUE), Float.MIN_VALUE);
check(new String(""+Float.MAX_VALUE), Float.MAX_VALUE);
check("10", (float) 10.0);
check("10.0", (float) 10.0);
check("10.01", (float) 10.01);
check("-10", (float) -10.0);
check("-10.00", (float) -10.0);
check("-10.01", (float) -10.01);
}
static String badStrings[] = {
"",
"+",
"-",
"+e",
"-e",
"+e170",
"-e170",
// Make sure intermediate white space is not deleted.
"1234 e10",
"-1234 e10",
// Control characters in the interior of a string are not legal
"1\u0007e1",
"1e\u00071",
// NaN and infinity can't have trailing type suffices or exponents
"NaNf",
"NaNF",
"NaNd",
"NaND",
"-NaNf",
"-NaNF",
"-NaNd",
"-NaND",
"+NaNf",
"+NaNF",
"+NaNd",
"+NaND",
"Infinityf",
"InfinityF",
"Infinityd",
"InfinityD",
"-Infinityf",
"-InfinityF",
"-Infinityd",
"-InfinityD",
"+Infinityf",
"+InfinityF",
"+Infinityd",
"+InfinityD",
"NaNe10",
"-NaNe10",
"+NaNe10",
"Infinitye10",
"-Infinitye10",
"+Infinitye10",
// Non-ASCII digits are not recognized
"\u0661e\u0661", // 1e1 in Arabic-Indic digits
"\u06F1e\u06F1", // 1e1 in Extended Arabic-Indic digits
"\u0967e\u0967" // 1e1 in Devanagari digits
};
static String goodStrings[] = {
"NaN",
"+NaN",
"-NaN",
"Infinity",
"+Infinity",
"-Infinity",
"1.1e-23f",
".1e-23f",
"1e-23",
"1f",
"1",
"2",
"1234",
"-1234",
"+1234",
"2147483647", // Integer.MAX_VALUE
"2147483648",
"-2147483648", // Integer.MIN_VALUE
"-2147483649",
"16777215",
"16777216", // 2^24
"16777217",
"-16777215",
"-16777216", // -2^24
"-16777217",
"9007199254740991",
"9007199254740992", // 2^53
"9007199254740993",
"-9007199254740991",
"-9007199254740992", // -2^53
"-9007199254740993",
"9223372036854775807",
"9223372036854775808", // Long.MAX_VALUE
"9223372036854775809",
"-9223372036854775808",
"-9223372036854775809", // Long.MIN_VALUE
"-9223372036854775810"
};
static String paddedBadStrings[];
static String paddedGoodStrings[];
static {
String pad = " \t\n\r\f\u0001\u000b\u001f";
paddedBadStrings = new String[badStrings.length];
for(int i = 0 ; i < badStrings.length; i++)
paddedBadStrings[i] = pad + badStrings[i] + pad;
paddedGoodStrings = new String[goodStrings.length];
for(int i = 0 ; i < goodStrings.length; i++)
paddedGoodStrings[i] = pad + goodStrings[i] + pad;
}
/*
* Throws an exception if <code>Input</code> is
* <code>exceptionalInput</code> and {@link Float.parseFloat
* parseFloat} does <em>not</em> throw an exception or if
* <code>Input</code> is not <code>exceptionalInput</code> and
* <code>parseFloat</code> throws an exception. This method does
* not attempt to test whether the string is converted to the
* proper value; just whether the input is accepted appropriately
* or not.
*/
private static void testParsing(String [] input,
boolean exceptionalInput) {
for(int i = 0; i < input.length; i++) {
double d;
try {
d = Float.parseFloat(input[i]);
}
catch (NumberFormatException e) {
if (! exceptionalInput) {
throw new RuntimeException("Float.parseFloat rejected " +
"good string `" + input[i] +
"'.");
}
break;
}
if (exceptionalInput) {
throw new RuntimeException("Float.parseFloat accepted " +
"bad string `" + input[i] +
"'.");
}
}
}
public static void main(String[] args) throws Exception {
rudimentaryTest();
testParsing(goodStrings, false);
testParsing(paddedGoodStrings, false);
testParsing(badStrings, true);
testParsing(paddedBadStrings, true);
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4495754
* @summary Basic test for int bit twiddling
* @author Josh Bloch
*
* @compile -source 1.5 BitTwiddle.java
* @run main BitTwiddle
*/
import java.util.Random;
import static java.lang.Integer.*;
public class BitTwiddle {
private static final int N = 1000; // # of repetitions per test
public static void main(String args[]) {
Random rnd = new Random();
if (highestOneBit(0) != 0)
throw new RuntimeException("a");
if (highestOneBit(-1) != MIN_VALUE)
throw new RuntimeException("b");
if (highestOneBit(1) != 1)
throw new RuntimeException("c");
if (lowestOneBit(0) != 0)
throw new RuntimeException("d");
if (lowestOneBit(-1) != 1)
throw new RuntimeException("e");
if (lowestOneBit(MIN_VALUE) != MIN_VALUE)
throw new RuntimeException("f");
for (int i = 0; i < N; i++) {
int x = rnd.nextInt();
if (highestOneBit(x) != reverse(lowestOneBit(reverse(x))))
throw new RuntimeException("g: " + toHexString(x));
}
if (numberOfLeadingZeros(0) != SIZE)
throw new RuntimeException("h");
if (numberOfLeadingZeros(-1) != 0)
throw new RuntimeException("i");
if (numberOfLeadingZeros(1) != (SIZE - 1))
throw new RuntimeException("j");
if (numberOfTrailingZeros(0) != SIZE)
throw new RuntimeException("k");
if (numberOfTrailingZeros(1) != 0)
throw new RuntimeException("l");
if (numberOfTrailingZeros(MIN_VALUE) != (SIZE - 1))
throw new RuntimeException("m");
for (int i = 0; i < N; i++) {
int x = rnd.nextInt();
if (numberOfLeadingZeros(x) != numberOfTrailingZeros(reverse(x)))
throw new RuntimeException("n: " + toHexString(x));
}
if (bitCount(0) != 0)
throw new RuntimeException("o");
for (int i = 0; i < SIZE; i++) {
int pow2 = 1 << i;
if (bitCount(pow2) != 1)
throw new RuntimeException("p: " + i);
if (bitCount(pow2 -1) != i)
throw new RuntimeException("q: " + i);
}
for (int i = 0; i < N; i++) {
int x = rnd.nextInt();
if (bitCount(x) != bitCount(reverse(x)))
throw new RuntimeException("r: " + toHexString(x));
}
for (int i = 0; i < N; i++) {
int x = rnd.nextInt();
int dist = rnd.nextInt();
if (bitCount(x) != bitCount(rotateRight(x, dist)))
throw new RuntimeException("s: " + toHexString(x) +
toHexString(dist));
if (bitCount(x) != bitCount(rotateLeft(x, dist)))
throw new RuntimeException("t: " + toHexString(x) +
toHexString(dist));
if (rotateRight(x, dist) != rotateLeft(x, -dist))
throw new RuntimeException("u: " + toHexString(x) +
toHexString(dist));
if (rotateRight(x, -dist) != rotateLeft(x, dist))
throw new RuntimeException("v: " + toHexString(x) +
toHexString(dist));
}
if (signum(0) != 0 || signum(1) != 1 || signum(-1) != -1
|| signum(MIN_VALUE) != -1 || signum(MAX_VALUE) != 1)
throw new RuntimeException("w");
for (int i = 0; i < N; i++) {
int x = rnd.nextInt();
int sign = (x < 0 ? -1 : (x == 0 ? 0 : 1));
if (signum(x) != sign)
throw new RuntimeException("x: " + toHexString(x));
}
if(reverseBytes(0xaabbccdd) != 0xddccbbaa)
throw new RuntimeException("y");
for (int i = 0; i < N; i++) {
int x = rnd.nextInt();
if (bitCount(x) != bitCount(reverseBytes(x)))
throw new RuntimeException("z: " + toHexString(x));
}
}
}
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4136371 5017980 6576055
* @summary Test Integer.decode method
* @author madbot
* @author Joseph D. Darcy
*/
/**
* There are six methods in java.lang.Integer which transform strings
* into an int or Integer value:
*
* public Integer(String s)
* public static Integer decode(String nm)
* public static int parseInteger(String s, int radix)
* public static int parseInteger(String s)
* public static Integer valueOf(String s, int radix)
* public static Integer valueOf(String s)
*
* The other five methods are tested elsewhere.
*/
public class Decode {
private static void check(String val, int expected) {
int n = (Integer.decode(val)).intValue();
if (n != expected)
throw new RuntimeException("Integer.decode failed. String:" +
val + " Result:" + n);
}
private static void checkFailure(String val, String message) {
try {
int n = (Integer.decode(val)).intValue();
throw new RuntimeException(message);
} catch (NumberFormatException e) { /* Okay */}
}
public static void main(String[] args) throws Exception {
check(new String(""+Integer.MIN_VALUE), Integer.MIN_VALUE);
check(new String(""+Integer.MAX_VALUE), Integer.MAX_VALUE);
check("10", 10);
check("0x10", 16);
check("0X10", 16);
check("010", 8);
check("#10", 16);
check("+10", 10);
check("+0x10", 16);
check("+0X10", 16);
check("+010", 8);
check("+#10", 16);
check("-10", -10);
check("-0x10", -16);
check("-0X10", -16);
check("-010", -8);
check("-#10", -16);
check(Long.toString(Integer.MIN_VALUE), Integer.MIN_VALUE);
check(Long.toString(Integer.MAX_VALUE), Integer.MAX_VALUE);
checkFailure("0x-10", "Integer.decode allows negative sign in wrong position.");
checkFailure("0x+10", "Integer.decode allows positive sign in wrong position.");
checkFailure("+", "Raw plus sign allowed.");
checkFailure("-", "Raw minus sign allowed.");
checkFailure(Long.toString((long)Integer.MIN_VALUE - 1L), "Out of range");
checkFailure(Long.toString((long)Integer.MAX_VALUE + 1L), "Out of range");
checkFailure("", "Empty String");
try {
Integer.decode(null);
throw new RuntimeException("Integer.decode(null) expected to throw NPE");
} catch (NullPointerException npe) {/* Okay */}
}
}
/*
* Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4252315
* @summary test Integer.getInteger method with empty key
*/
public class GetInteger {
public static void main(String[] args) throws Exception {
Integer.getInteger("", 1);
Integer.getInteger(null, 1);
}
}
/*
* Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5017980 6576055
* @summary Test parsing methods
* @author Joseph D. Darcy
*/
/**
* There are six methods in java.lang.Integer which transform strings
* into an int or Integer value:
*
* public Integer(String s)
* public static Integer decode(String nm)
* public static int parseInt(String s, int radix)
* public static int parseInt(String s)
* public static Integer valueOf(String s, int radix)
* public static Integer valueOf(String s)
*
* Besides decode, all the methods and constructor call down into
* parseInt(String, int) to do the actual work. Therefore, the
* behavior of parseInt(String, int) will be tested here.
*/
public class ParsingTest {
public static void main(String... argv) {
check("+100", +100);
check("-100", -100);
check("+0", 0);
check("-0", 0);
check("+00000", 0);
check("-00000", 0);
check("0", 0);
check("1", 1);
check("9", 9);
checkFailure("\u0000");
checkFailure("\u002f");
checkFailure("+");
checkFailure("-");
checkFailure("++");
checkFailure("+-");
checkFailure("-+");
checkFailure("--");
checkFailure("++100");
checkFailure("--100");
checkFailure("+-6");
checkFailure("-+6");
checkFailure("*100");
}
private static void check(String val, int expected) {
int n = Integer.parseInt(val);
if (n != expected)
throw new RuntimeException("Integer.parsedInt failed. String:" +
val + " Result:" + n);
}
private static void checkFailure(String val) {
int n = 0;
try {
n = Integer.parseInt(val);
System.err.println("parseInt(" + val + ") incorrectly returned " + n);
throw new RuntimeException();
} catch (NumberFormatException nfe) {
; // Expected
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4495754
* @summary Basic test for long bit twiddling
* @author Josh Bloch
*
* @compile -source 1.5 BitTwiddle.java
* @run main BitTwiddle
*/
import java.util.Random;
import static java.lang.Long.*;
public class BitTwiddle {
private static final int N = 1000; // # of repetitions per test
public static void main(String args[]) {
Random rnd = new Random();
if (highestOneBit(0) != 0)
throw new RuntimeException("a");
if (highestOneBit(-1) != MIN_VALUE)
throw new RuntimeException("b");
if (highestOneBit(1) != 1)
throw new RuntimeException("c");
if (lowestOneBit(0) != 0)
throw new RuntimeException("d");
if (lowestOneBit(-1) != 1)
throw new RuntimeException("e");
if (lowestOneBit(MIN_VALUE) != MIN_VALUE)
throw new RuntimeException("f");
for (int i = 0; i < N; i++) {
long x = rnd.nextLong();
if (highestOneBit(x) != reverse(lowestOneBit(reverse(x))))
throw new RuntimeException("g: " + toHexString(x));
}
if (numberOfLeadingZeros(0) != SIZE)
throw new RuntimeException("h");
if (numberOfLeadingZeros(-1) != 0)
throw new RuntimeException("i");
if (numberOfLeadingZeros(1) != (SIZE - 1))
throw new RuntimeException("j");
if (numberOfTrailingZeros(0) != SIZE)
throw new RuntimeException("k");
if (numberOfTrailingZeros(1) != 0)
throw new RuntimeException("l");
if (numberOfTrailingZeros(MIN_VALUE) != (SIZE - 1))
throw new RuntimeException("m");
for (int i = 0; i < N; i++) {
long x = rnd.nextLong();
if (numberOfLeadingZeros(x) != numberOfTrailingZeros(reverse(x)))
throw new RuntimeException("n: " + toHexString(x));
}
if (bitCount(0) != 0)
throw new RuntimeException("o");
for (int i = 0; i < SIZE; i++) {
long pow2 = 1L << i;
if (bitCount(pow2) != 1)
throw new RuntimeException("p: " + i);
if (bitCount(pow2 -1) != i)
throw new RuntimeException("q: " + i);
}
for (int i = 0; i < N; i++) {
long x = rnd.nextLong();
if (bitCount(x) != bitCount(reverse(x)))
throw new RuntimeException("r: " + toHexString(x));
}
for (int i = 0; i < N; i++) {
long x = rnd.nextLong();
int dist = rnd.nextInt();
if (bitCount(x) != bitCount(rotateRight(x, dist)))
throw new RuntimeException("s: " + toHexString(x) +
toHexString(dist));
if (bitCount(x) != bitCount(rotateLeft(x, dist)))
throw new RuntimeException("t: " + toHexString(x) +
toHexString(dist));
if (rotateRight(x, dist) != rotateLeft(x, -dist))
throw new RuntimeException("u: " + toHexString(x) +
toHexString(dist));
if (rotateRight(x, -dist) != rotateLeft(x, dist))
throw new RuntimeException("v: " + toHexString(x) +
toHexString(dist));
}
if (signum(0) != 0 || signum(1) != 1 || signum(-1) != -1
|| signum(MIN_VALUE) != -1 || signum(MAX_VALUE) != 1)
throw new RuntimeException("w");
for (int i = 0; i < N; i++) {
long x = rnd.nextLong();
int sign = (x < 0 ? -1 : (x == 0 ? 0 : 1));
if (signum(x) != sign)
throw new RuntimeException("x: " + toHexString(x));
}
if(reverseBytes(0xaabbccdd11223344L) != 0x44332211ddccbbaaL)
throw new RuntimeException("y");
for (int i = 0; i < N; i++) {
long x = rnd.nextLong();
if (bitCount(x) != bitCount(reverseBytes(x)))
throw new RuntimeException("z: " + toHexString(x));
}
}
}
/*
* Copyright 1998-2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4136371 5017980 6576055
* @summary Test Long.decode method
* @author madbot
* @author Joseph D. Darcy
*/
import java.math.BigInteger;
/**
* There are six methods in java.lang.Integer which transform strings
* into a long or Long value:
*
* public Long(String s)
* public static Long decode(String nm)
* public static long parseLong(String s, int radix)
* public static long parseLong(String s)
* public static Long valueOf(String s, int radix)
* public static Long valueOf(String s)
*
* The other five methods are tested elsewhere.
*/
public class Decode {
private static void check(String val, long expected) {
long n = (Long.decode(val)).longValue();
if (n != expected)
throw new RuntimeException("Long.decode failed. String:" +
val + " Result:" + n);
}
private static void checkFailure(String val, String message) {
try {
long n = (Long.decode(val)).longValue();
throw new RuntimeException(message);
} catch (NumberFormatException e) { /* Okay */}
}
public static void main(String[] args) throws Exception {
check(new String(""+Long.MIN_VALUE), Long.MIN_VALUE);
check(new String(""+Long.MAX_VALUE), Long.MAX_VALUE);
check("10", 10L);
check("0x10", 16L);
check("0X10", 16L);
check("010", 8L);
check("#10", 16L);
check("+10", 10L);
check("+0x10", 16L);
check("+0X10", 16L);
check("+010", 8L);
check("+#10", 16L);
check("-10", -10L);
check("-0x10", -16L);
check("-0X10", -16L);
check("-010", -8L);
check("-#10", -16L);
check(Long.toString(Long.MIN_VALUE), Long.MIN_VALUE);
check(Long.toString(Long.MAX_VALUE), Long.MAX_VALUE);
checkFailure("0x-10", "Long.decode allows negative sign in wrong position.");
checkFailure("0x+10", "Long.decode allows positive sign in wrong position.");
checkFailure("+", "Raw plus sign allowed.");
checkFailure("-", "Raw minus sign allowed.");
checkFailure(BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE).toString(),
"Out of range");
checkFailure(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE).toString(),
"Out of range");
checkFailure("", "Empty String");
try {
Long.decode(null);
throw new RuntimeException("Long.decode(null) expected to throw NPE");
} catch (NullPointerException npe) {/* Okay */}
}
}
/*
* Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4252322
* @summary test Long.getLong method with empty key
*/
public class GetLong {
public static void main(String[] args) throws Exception {
Long.getLong("", 1);
Long.getLong(null, 1);
}
}
/*
* Copyright 2006-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5017980 6576055
* @summary Test parsing methods
* @author Joseph D. Darcy
*/
/**
* There are six methods in java.lang.Long which transform strings
* into a long or Long value:
*
* public Long(String s)
* public static Long decode(String nm)
* public static long parseLong(String s, int radix)
* public static long parseLong(String s)
* public static Long valueOf(String s, int radix)
* public static Long valueOf(String s)
*
* Besides decode, all the methods and constructor call down into
* parseLong(String, int) to do the actual work. Therefore, the
* behavior of parseLong(String, int) will be tested here.
*/
public class ParsingTest {
public static void main(String... argv) {
check("+100", +100L);
check("-100", -100L);
check("+0", 0L);
check("-0", 0L);
check("+00000", 0L);
check("-00000", 0L);
check("0", 0L);
check("1", 1L);
check("9", 9L);
checkFailure("\u0000");
checkFailure("\u002f");
checkFailure("+");
checkFailure("-");
checkFailure("++");
checkFailure("+-");
checkFailure("-+");
checkFailure("--");
checkFailure("++100");
checkFailure("--100");
checkFailure("+-6");
checkFailure("-+6");
checkFailure("*100");
}
private static void check(String val, long expected) {
long n = Long.parseLong(val);
if (n != expected)
throw new RuntimeException("Long.parsedLong failed. String:" +
val + " Result:" + n);
}
private static void checkFailure(String val) {
long n = 0L;
try {
n = Long.parseLong(val);
System.err.println("parseLong(" + val + ") incorrectly returned " + n);
throw new RuntimeException();
} catch (NumberFormatException nfe) {
; // Expected
}
}
}
/*
* Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
@bug 4096278
@summary Math.abs(+0.0) wrong
@author Anand Palaniswamy
*/
public class AbsPositiveZero {
private static boolean isPositiveZero(float f) {
return Float.floatToIntBits(f) == Float.floatToIntBits(0.0f);
}
private static boolean isPositiveZero(double d) {
return Double.doubleToLongBits(d) == Double.doubleToLongBits(0.0d);
}
public static void main(String[] args) throws Exception {
if (!isPositiveZero(Math.abs(-0.0d))) {
throw new Exception("abs(-0.0d) failed");
}
if (!isPositiveZero(Math.abs(+0.0d))) {
throw new Exception("abs(+0.0d) failed");
}
if (Math.abs(Double.POSITIVE_INFINITY) != Double.POSITIVE_INFINITY) {
throw new Exception("abs(+Inf) failed");
}
if (Math.abs(Double.NEGATIVE_INFINITY) != Double.POSITIVE_INFINITY) {
throw new Exception("abs(-Inf) failed");
}
double dnanval = Math.abs(Double.NaN);
if (dnanval == dnanval) {
throw new Exception("abs(NaN) failed");
}
if (!isPositiveZero(Math.abs(-0.0f))) {
throw new Exception("abs(-0.0f) failed");
}
if (!isPositiveZero(Math.abs(+0.0f))) {
throw new Exception("abs(+0.0f) failed");
}
if (Math.abs(Float.POSITIVE_INFINITY) != Float.POSITIVE_INFINITY) {
throw new Exception("abs(+Inf) failed");
}
if (Math.abs(Float.NEGATIVE_INFINITY) != Float.POSITIVE_INFINITY) {
throw new Exception("abs(-Inf) failed");
}
float fnanval = Math.abs(Float.NaN);
if (fnanval == fnanval) {
throw new Exception("abs(NaN) failed");
}
}
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4984407
* @summary Tests for {Math, StrictMath}.atan2
* @compile -source 1.5 Atan2Tests.java
* @run main Atan2Tests
* @author Joseph D. Darcy
*/
public class Atan2Tests {
private Atan2Tests(){}
static int testAtan2Case(double input1, double input2, double expected) {
int failures = 0;
failures += Tests.test("StrictMath.atan2(double, double)", input1, input2,
StrictMath.atan2(input1, input2), expected);
failures += Tests.test("Math.atan2(double, double)", input1, input2,
Math.atan2(input1, input2), expected);
return failures;
}
static int testAtan2() {
int failures = 0;
double [][] testCases = {
{-3.0, Double.POSITIVE_INFINITY, -0.0},
};
for (double[] testCase : testCases) {
failures+=testAtan2Case(testCase[0], testCase[1], testCase[2]);
}
return failures;
}
public static void main(String [] argv) {
int failures = 0;
failures += testAtan2();
if (failures > 0) {
System.err.println("Testing atan2 incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4347132 4939441
* @summary Tests for {Math, StrictMath}.cbrt
* @author Joseph D. Darcy
*/
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class CubeRootTests {
private CubeRootTests(){}
static final double infinityD = Double.POSITIVE_INFINITY;
static final double NaNd = Double.NaN;
// Initialize shared random number generator
static java.util.Random rand = new java.util.Random();
static int testCubeRootCase(double input, double expected) {
int failures=0;
double minus_input = -input;
double minus_expected = -expected;
failures+=Tests.test("Math.cbrt(double)", input,
Math.cbrt(input), expected);
failures+=Tests.test("Math.cbrt(double)", minus_input,
Math.cbrt(minus_input), minus_expected);
failures+=Tests.test("StrictMath.cbrt(double)", input,
StrictMath.cbrt(input), expected);
failures+=Tests.test("StrictMath.cbrt(double)", minus_input,
StrictMath.cbrt(minus_input), minus_expected);
return failures;
}
static int testCubeRoot() {
int failures = 0;
double [][] testCases = {
{NaNd, NaNd},
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY},
{Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY},
{+0.0, +0.0},
{-0.0, -0.0},
{+1.0, +1.0},
{-1.0, -1.0},
{+8.0, +2.0},
{-8.0, -2.0}
};
for(int i = 0; i < testCases.length; i++) {
failures += testCubeRootCase(testCases[i][0],
testCases[i][1]);
}
// Test integer perfect cubes less than 2^53.
for(int i = 0; i <= 208063; i++) {
double d = i;
failures += testCubeRootCase(d*d*d, (double)i);
}
// Test cbrt(2^(3n)) = 2^n.
for(int i = 18; i <= DoubleConsts.MAX_EXPONENT/3; i++) {
failures += testCubeRootCase(FpUtils.scalb(1.0, 3*i),
FpUtils.scalb(1.0, i) );
}
// Test cbrt(2^(-3n)) = 2^-n.
for(int i = -1; i >= FpUtils.ilogb(Double.MIN_VALUE)/3; i--) {
failures += testCubeRootCase(FpUtils.scalb(1.0, 3*i),
FpUtils.scalb(1.0, i) );
}
// Test random perfect cubes. Create double values with
// modest exponents but only have at most the 17 most
// significant bits in the significand set; 17*3 = 51, which
// is less than the number of bits in a double's significand.
long exponentBits1 =
Double.doubleToLongBits(FpUtils.scalb(1.0, 55)) &
DoubleConsts.EXP_BIT_MASK;
long exponentBits2=
Double.doubleToLongBits(FpUtils.scalb(1.0, -55)) &
DoubleConsts.EXP_BIT_MASK;
for(int i = 0; i < 100; i++) {
// Take 16 bits since the 17th bit is implicit in the
// exponent
double input1 =
Double.longBitsToDouble(exponentBits1 |
// Significand bits
((long) (rand.nextInt() & 0xFFFF))<<
(DoubleConsts.SIGNIFICAND_WIDTH-1-16));
failures += testCubeRootCase(input1*input1*input1, input1);
double input2 =
Double.longBitsToDouble(exponentBits2 |
// Significand bits
((long) (rand.nextInt() & 0xFFFF))<<
(DoubleConsts.SIGNIFICAND_WIDTH-1-16));
failures += testCubeRootCase(input2*input2*input2, input2);
}
// Directly test quality of implementation properties of cbrt
// for values that aren't perfect cubes. Verify returned
// result meets the 1 ulp test. That is, we want to verify
// that for positive x > 1,
// y = cbrt(x),
//
// if (err1=x - y^3 ) < 0, abs((y_pp^3 -x )) < err1
// if (err1=x - y^3 ) > 0, abs((y_mm^3 -x )) < err1
//
// where y_mm and y_pp are the next smaller and next larger
// floating-point value to y. In other words, if y^3 is too
// big, making y larger does not improve the result; likewise,
// if y^3 is too small, making y smaller does not improve the
// result.
//
// ...-----|--?--|--?--|-----... Where is the true result?
// y_mm y y_pp
//
// The returned value y should be one of the floating-point
// values braketing the true result. However, given y, a
// priori we don't know if the true result falls in [y_mm, y]
// or [y, y_pp]. The above test looks at the error in x-y^3
// to determine which region the true result is in; e.g. if
// y^3 is smaller than x, the true result should be in [y,
// y_pp]. Therefore, it would be an error for y_mm to be a
// closer approximation to x^(1/3). In this case, it is
// permissible, although not ideal, for y_pp^3 to be a closer
// approximation to x^(1/3) than y^3.
//
// We will use pow(y,3) to compute y^3. Although pow is not
// correctly rounded, StrictMath.pow should have at most 1 ulp
// error. For y > 1, pow(y_mm,3) and pow(y_pp,3) will differ
// from pow(y,3) by more than one ulp so the comparision of
// errors should still be valid.
for(int i = 0; i < 1000; i++) {
double d = 1.0 + rand.nextDouble();
double err, err_adjacent;
double y1 = Math.cbrt(d);
double y2 = StrictMath.cbrt(d);
err = d - StrictMath.pow(y1, 3);
if (err != 0.0) {
if(FpUtils.isNaN(err)) {
failures++;
System.err.println("Encountered unexpected NaN value: d = " + d +
"\tcbrt(d) = " + y1);
} else {
if (err < 0.0) {
err_adjacent = StrictMath.pow(FpUtils.nextUp(y1), 3) - d;
}
else { // (err > 0.0)
err_adjacent = StrictMath.pow(FpUtils.nextAfter(y1,0.0), 3) - d;
}
if (Math.abs(err) > Math.abs(err_adjacent)) {
failures++;
System.err.println("For Math.cbrt(" + d + "), returned result " +
y1 + "is not as good as adjacent value.");
}
}
}
err = d - StrictMath.pow(y2, 3);
if (err != 0.0) {
if(FpUtils.isNaN(err)) {
failures++;
System.err.println("Encountered unexpected NaN value: d = " + d +
"\tcbrt(d) = " + y2);
} else {
if (err < 0.0) {
err_adjacent = StrictMath.pow(FpUtils.nextUp(y2), 3) - d;
}
else { // (err > 0.0)
err_adjacent = StrictMath.pow(FpUtils.nextAfter(y2,0.0), 3) - d;
}
if (Math.abs(err) > Math.abs(err_adjacent)) {
failures++;
System.err.println("For StrictMath.cbrt(" + d + "), returned result " +
y2 + "is not as good as adjacent value.");
}
}
}
}
// Test monotonicity properites near perfect cubes; test two
// numbers before and two numbers after; i.e. for
//
// pcNeighbors[] =
// {nextDown(nextDown(pc)),
// nextDown(pc),
// pc,
// nextUp(pc),
// nextUp(nextUp(pc))}
//
// test that cbrt(pcNeighbors[i]) <= cbrt(pcNeighbors[i+1])
{
double pcNeighbors[] = new double[5];
double pcNeighborsCbrt[] = new double[5];
double pcNeighborsStrictCbrt[] = new double[5];
// Test near cbrt(2^(3n)) = 2^n.
for(int i = 18; i <= DoubleConsts.MAX_EXPONENT/3; i++) {
double pc = FpUtils.scalb(1.0, 3*i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[3] = FpUtils.nextUp(pc);
pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsCbrt[j] = Math.cbrt(pcNeighbors[j]);
pcNeighborsStrictCbrt[j] = StrictMath.cbrt(pcNeighbors[j]);
}
for(int j = 0; j < pcNeighborsCbrt.length-1; j++) {
if(pcNeighborsCbrt[j] > pcNeighborsCbrt[j+1] ) {
failures++;
System.err.println("Monotonicity failure for Math.cbrt on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsCbrt[j] + " and " +
pcNeighborsCbrt[j+1] );
}
if(pcNeighborsStrictCbrt[j] > pcNeighborsStrictCbrt[j+1] ) {
failures++;
System.err.println("Monotonicity failure for StrictMath.cbrt on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsStrictCbrt[j] + " and " +
pcNeighborsStrictCbrt[j+1] );
}
}
}
// Test near cbrt(2^(-3n)) = 2^-n.
for(int i = -1; i >= FpUtils.ilogb(Double.MIN_VALUE)/3; i--) {
double pc = FpUtils.scalb(1.0, 3*i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[3] = FpUtils.nextUp(pc);
pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsCbrt[j] = Math.cbrt(pcNeighbors[j]);
pcNeighborsStrictCbrt[j] = StrictMath.cbrt(pcNeighbors[j]);
}
for(int j = 0; j < pcNeighborsCbrt.length-1; j++) {
if(pcNeighborsCbrt[j] > pcNeighborsCbrt[j+1] ) {
failures++;
System.err.println("Monotonicity failure for Math.cbrt on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsCbrt[j] + " and " +
pcNeighborsCbrt[j+1] );
}
if(pcNeighborsStrictCbrt[j] > pcNeighborsStrictCbrt[j+1] ) {
failures++;
System.err.println("Monotonicity failure for StrictMath.cbrt on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsStrictCbrt[j] + " and " +
pcNeighborsStrictCbrt[j+1] );
}
}
}
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += testCubeRoot();
if (failures > 0) {
System.err.println("Testing cbrt incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851638 4900189 4939441
* @summary Tests for {Math, StrictMath}.expm1
* @author Joseph D. Darcy
*/
import sun.misc.DoubleConsts;
import sun.misc.FpUtils;
/*
* The Taylor expansion of expxm1(x) = exp(x) -1 is
*
* 1 + x/1! + x^2/2! + x^3/3| + ... -1 =
*
* x + x^2/2! + x^3/3 + ...
*
* Therefore, for small values of x, expxm1 ~= x.
*
* For large values of x, expxm1(x) ~= exp(x)
*
* For large negative x, expxm1(x) ~= -1.
*/
public class Expm1Tests {
private Expm1Tests(){}
static final double infinityD = Double.POSITIVE_INFINITY;
static final double NaNd = Double.NaN;
static int testExpm1() {
int failures = 0;
double [][] testCases = {
{Double.NaN, NaNd},
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
{infinityD, infinityD},
{-infinityD, -1.0},
{-0.0, -0.0},
{+0.0, +0.0},
};
// Test special cases
for(int i = 0; i < testCases.length; i++) {
failures += testExpm1CaseWithUlpDiff(testCases[i][0],
testCases[i][1], 0, null);
}
// For |x| < 2^-54 expm1(x) ~= x
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i <= -54; i++) {
double d = FpUtils.scalb(2, i);
failures += testExpm1Case(d, d);
failures += testExpm1Case(-d, -d);
}
// For values of y where exp(y) > 2^54, expm1(x) ~= exp(x).
// The least such y is ln(2^54) ~= 37.42994775023705; exp(x)
// overflows for x > ~= 709.8
// Use a 2-ulp error threshold to account for errors in the
// exp implementation; the increments of d in the loop will be
// exact.
for(double d = 37.5; d <= 709.5; d += 1.0) {
failures += testExpm1CaseWithUlpDiff(d, StrictMath.exp(d), 2, null);
}
// For x > 710, expm1(x) should be infinity
for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
double d = FpUtils.scalb(2, i);
failures += testExpm1Case(d, infinityD);
}
// By monotonicity, once the limit is reached, the
// implemenation should return the limit for all smaller
// values.
boolean reachedLimit [] = {false, false};
// Once exp(y) < 0.5 * ulp(1), expm1(y) ~= -1.0;
// The greatest such y is ln(2^-53) ~= -36.7368005696771.
for(double d = -36.75; d >= -127.75; d -= 1.0) {
failures += testExpm1CaseWithUlpDiff(d, -1.0, 1,
reachedLimit);
}
for(int i = 7; i <= DoubleConsts.MAX_EXPONENT; i++) {
double d = -FpUtils.scalb(2, i);
failures += testExpm1CaseWithUlpDiff(d, -1.0, 1, reachedLimit);
}
// Test for monotonicity failures near multiples of log(2).
// Test two numbers before and two numbers after each chosen
// value; i.e.
//
// pcNeighbors[] =
// {nextDown(nextDown(pc)),
// nextDown(pc),
// pc,
// nextUp(pc),
// nextUp(nextUp(pc))}
//
// and we test that expm1(pcNeighbors[i]) <= expm1(pcNeighbors[i+1])
{
double pcNeighbors[] = new double[5];
double pcNeighborsExpm1[] = new double[5];
double pcNeighborsStrictExpm1[] = new double[5];
for(int i = -50; i <= 50; i++) {
double pc = StrictMath.log(2)*i;
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[3] = FpUtils.nextUp(pc);
pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsExpm1[j] = Math.expm1(pcNeighbors[j]);
pcNeighborsStrictExpm1[j] = StrictMath.expm1(pcNeighbors[j]);
}
for(int j = 0; j < pcNeighborsExpm1.length-1; j++) {
if(pcNeighborsExpm1[j] > pcNeighborsExpm1[j+1] ) {
failures++;
System.err.println("Monotonicity failure for Math.expm1 on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsExpm1[j] + " and " +
pcNeighborsExpm1[j+1] );
}
if(pcNeighborsStrictExpm1[j] > pcNeighborsStrictExpm1[j+1] ) {
failures++;
System.err.println("Monotonicity failure for StrictMath.expm1 on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsStrictExpm1[j] + " and " +
pcNeighborsStrictExpm1[j+1] );
}
}
}
}
return failures;
}
public static int testExpm1Case(double input,
double expected) {
return testExpm1CaseWithUlpDiff(input, expected, 1, null);
}
public static int testExpm1CaseWithUlpDiff(double input,
double expected,
double ulps,
boolean [] reachedLimit) {
int failures = 0;
double mathUlps = ulps, strictUlps = ulps;
double mathOutput;
double strictOutput;
if (reachedLimit != null) {
if (reachedLimit[0])
mathUlps = 0;
if (reachedLimit[1])
strictUlps = 0;
}
failures += Tests.testUlpDiffWithLowerBound("Math.expm1(double)",
input, mathOutput=Math.expm1(input),
expected, mathUlps, -1.0);
failures += Tests.testUlpDiffWithLowerBound("StrictMath.expm1(double)",
input, strictOutput=StrictMath.expm1(input),
expected, strictUlps, -1.0);
if (reachedLimit != null) {
reachedLimit[0] |= (mathOutput == -1.0);
reachedLimit[1] |= (strictOutput == -1.0);
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += testExpm1();
if (failures > 0) {
System.err.println("Testing expm1 incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851625 4900189 4939441
* @summary Tests for {Math, StrictMath}.{sinh, cosh, tanh}
* @author Joseph D. Darcy
*/
import sun.misc.DoubleConsts;
import sun.misc.FpUtils;
public class HyperbolicTests {
private HyperbolicTests(){}
static final double NaNd = Double.NaN;
/**
* Test accuracy of {Math, StrictMath}.sinh. The specified
* accuracy is 2.5 ulps.
*
* The defintion of sinh(x) is
*
* (e^x - e^(-x))/2
*
* The series expansion of sinh(x) =
*
* x + x^3/3! + x^5/5! + x^7/7! +...
*
* Therefore,
*
* 1. For large values of x sinh(x) ~= signum(x)*exp(|x|)/2
*
* 2. For small values of x, sinh(x) ~= x.
*
* Additionally, sinh is an odd function; sinh(-x) = -sinh(x).
*
*/
static int testSinh() {
int failures = 0;
/*
* Array elements below generated using a quad sinh
* implementation. Rounded to a double, the quad result
* *should* be correctly rounded, unless we are quite unlucky.
* Assuming the quad value is a correctly rounded double, the
* allowed error is 3.0 ulps instead of 2.5 since the quad
* value rounded to double can have its own 1/2 ulp error.
*/
double [][] testCases = {
// x sinh(x)
{0.0625, 0.06254069805219182172183988501029229},
{0.1250, 0.12532577524111545698205754229137154},
{0.1875, 0.18860056562029018382047025055167585},
{0.2500, 0.25261231680816830791412515054205787},
{0.3125, 0.31761115611357728583959867611490292},
{0.3750, 0.38385106791361456875429567642050245},
{0.4375, 0.45159088610312053032509815226723017},
{0.5000, 0.52109530549374736162242562641149155},
{0.5625, 0.59263591611468777373870867338492247},
{0.6250, 0.66649226445661608227260655608302908},
{0.6875, 0.74295294580567543571442036910465007},
{0.7500, 0.82231673193582998070366163444691386},
{0.8125, 0.90489373856606433650504536421491368},
{0.8750, 0.99100663714429475605317427568995231},
{0.9375, 1.08099191569306394011007867453992548},
{1.0000, 1.17520119364380145688238185059560082},
{1.0625, 1.27400259579739321279181130344911907},
{1.1250, 1.37778219077984075760379987065228373},
{1.1875, 1.48694549961380717221109202361777593},
{1.2500, 1.60191908030082563790283030151221415},
{1.3125, 1.72315219460596010219069206464391528},
{1.3750, 1.85111856355791532419998548438506416},
{1.4375, 1.98631821852425112898943304217629457},
{1.5000, 2.12927945509481749683438749467763195},
{1.5625, 2.28056089740825247058075476705718764},
{1.6250, 2.44075368098794353221372986997161132},
{1.6875, 2.61048376261693140366028569794027603},
{1.7500, 2.79041436627764265509289122308816092},
{1.8125, 2.98124857471401377943765253243875520},
{1.8750, 3.18373207674259205101326780071803724},
{1.9375, 3.39865608104779099764440244167531810},
{2.0000, 3.62686040784701876766821398280126192},
{2.0625, 3.86923677050642806693938384073620450},
{2.1250, 4.12673225993027252260441410537905269},
{2.1875, 4.40035304533919660406976249684469164},
{2.2500, 4.69116830589833069188357567763552003},
{2.3125, 5.00031440855811351554075363240262157},
{2.3750, 5.32899934843284576394645856548481489},
{2.4375, 5.67850746906785056212578751630266858},
{2.5000, 6.05020448103978732145032363835040319},
{2.5625, 6.44554279850040875063706020260185553},
{2.6250, 6.86606721451642172826145238779845813},
{2.6875, 7.31342093738196587585692115636603571},
{2.7500, 7.78935201149073201875513401029935330},
{2.8125, 8.29572014785741787167717932988491961},
{2.8750, 8.83450399097893197351853322827892144},
{2.9375, 9.40780885043076394429977972921690859},
{3.0000, 10.01787492740990189897459361946582867},
{3.0625, 10.66708606836969224165124519209968368},
{3.1250, 11.35797907995166028304704128775698426},
{3.1875, 12.09325364161259019614431093344260209},
{3.2500, 12.87578285468067003959660391705481220},
{3.3125, 13.70862446906136798063935858393686525},
{3.3750, 14.59503283146163690015482636921657975},
{3.4375, 15.53847160182039311025096666980558478},
{3.5000, 16.54262728763499762495673152901249743},
{3.5625, 17.61142364906941482858466494889121694},
{3.6250, 18.74903703113232171399165788088277979},
{3.6875, 19.95991268283598684128844120984214675},
{3.7500, 21.24878212710338697364101071825171163},
{3.8125, 22.62068164929685091969259499078125023},
{3.8750, 24.08097197661255803883403419733891573},
{3.9375, 25.63535922523855307175060244757748997},
{4.0000, 27.28991719712775244890827159079382096},
{4.0625, 29.05111111351106713777825462100160185},
{4.1250, 30.92582287788986031725487699744107092},
{4.1875, 32.92137796722343190618721270937061472},
{4.2500, 35.04557405638942942322929652461901154},
{4.3125, 37.30671148776788628118833357170042385},
{4.3750, 39.71362570500944929025069048612806024},
{4.4375, 42.27572177772344954814418332587050658},
{4.5000, 45.00301115199178562180965680564371424},
{4.5625, 47.90615077031205065685078058248081891},
{4.6250, 50.99648471383193131253995134526177467},
{4.6875, 54.28608852959281437757368957713936555},
{4.7500, 57.78781641599226874961859781628591635},
{4.8125, 61.51535145084362283008545918273109379},
{4.8750, 65.48325905829987165560146562921543361},
{4.9375, 69.70704392356508084094318094283346381},
{5.0000, 74.20321057778875897700947199606456364},
{5.0625, 78.98932788987998983462810080907521151},
{5.1250, 84.08409771724448958901392613147384951},
{5.1875, 89.50742798369883598816307922895346849},
{5.2500, 95.28051047011540739630959111303975956},
{5.3125, 101.42590362176666730633859252034238987},
{5.3750, 107.96762069594029162704530843962700133},
{5.4375, 114.93122359426386042048760580590182604},
{5.5000, 122.34392274639096192409774240457730721},
{5.5625, 130.23468343534638291488502321709913206},
{5.6250, 138.63433897999898233879574111119546728},
{5.6875, 147.57571121692522056519568264304815790},
{5.7500, 157.09373875244884423880085377625986165},
{5.8125, 167.22561348600435888568183143777868662},
{5.8750, 178.01092593829229887752609866133883987},
{5.9375, 189.49181995209921964640216682906501778},
{6.0000, 201.71315737027922812498206768797872263},
{6.0625, 214.72269333437984291483666459592578915},
{6.1250, 228.57126288889537420461281285729970085},
{6.1875, 243.31297962030799867970551767086092471},
{6.2500, 259.00544710710289911522315435345489966},
{6.3125, 275.70998400700299790136562219920451185},
{6.3750, 293.49186366095654566861661249898332253},
{6.4375, 312.42056915013535342987623229485223434},
{6.5000, 332.57006480258443156075705566965111346},
{6.5625, 354.01908521044116928437570109827956007},
{6.6250, 376.85144288706511933454985188849781703},
{6.6875, 401.15635576625530823119100750634165252},
{6.7500, 427.02879582326538080306830640235938517},
{6.8125, 454.56986017986077163530945733572724452},
{6.8750, 483.88716614351897894746751705315210621},
{6.9375, 515.09527172439720070161654727225752288},
{7.0000, 548.31612327324652237375611757601851598},
{7.0625, 583.67953198942753384680988096024373270},
{7.1250, 621.32368116099280160364794462812762880},
{7.1875, 661.39566611888784148449430491465857519},
{7.2500, 704.05206901515336623551137120663358760},
{7.3125, 749.45957067108712382864538206200700256},
{7.3750, 797.79560188617531521347351754559776282},
{7.4375, 849.24903675279739482863565789325699416},
{7.5000, 904.02093068584652953510919038935849651},
{7.5625, 962.32530605113249628368993221570636328},
{7.6250, 1024.38998846242707559349318193113614698},
{7.6875, 1090.45749701500081956792547346904792325},
{7.7500, 1160.78599193425808533255719118417856088},
{7.8125, 1235.65028334242796895820912936318532502},
{7.8750, 1315.34290508508890654067255740428824014},
{7.9375, 1400.17525781352742299995139486063802583},
{8.0000, 1490.47882578955018611587663903188144796},
{8.0625, 1586.60647216744061169450001100145859236},
{8.1250, 1688.93381781440241350635231605477507900},
{8.1875, 1797.86070905726094477721128358866360644},
{8.2500, 1913.81278009067446281883262689250118009},
{8.3125, 2037.24311615199935553277163192983440062},
{8.3750, 2168.63402396170125867037749369723761636},
{8.4375, 2308.49891634734644432370720900969004306},
{8.5000, 2457.38431841538268239359965370719928775},
{8.5625, 2615.87200310986940554256648824234335262},
{8.6250, 2784.58126450289932429469130598902487336},
{8.6875, 2964.17133769964321637973459949999057146},
{8.7500, 3155.34397481384944060352507473513108710},
{8.8125, 3358.84618707947841898217318996045550438},
{8.8750, 3575.47316381333288862617411467285480067},
{8.9375, 3806.07137963459383403903729660349293583},
{9.0000, 4051.54190208278996051522359589803425598},
{9.0625, 4312.84391255878980330955246931164633615},
{9.1250, 4590.99845434696991399363282718106006883},
{9.1875, 4887.09242236403719571363798584676797558},
{9.2500, 5202.28281022453561319352901552085348309},
{9.3125, 5537.80123121853803935727335892054791265},
{9.3750, 5894.95873086734181634245918412592155656},
{9.4375, 6275.15090986233399457103055108344546942},
{9.5000, 6679.86337740502119410058225086262108741},
{9.5625, 7110.67755625726876329967852256934334025},
{9.6250, 7569.27686218510919585241049433331592115},
{9.6875, 8057.45328194243077504648484392156371121},
{9.7500, 8577.11437549816065709098061006273039092},
{9.8125, 9130.29072986829727910801024120918114778},
{9.8750, 9719.14389367880274015504995181862860062},
{9.9375, 10345.97482346383208590278839409938269134},
{10.0000, 11013.23287470339337723652455484636420303},
};
for(int i = 0; i < testCases.length; i++) {
double [] testCase = testCases[i];
failures += testSinhCaseWithUlpDiff(testCase[0],
testCase[1],
3.0);
}
double [][] specialTestCases = {
{0.0, 0.0},
{NaNd, NaNd},
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}
};
for(int i = 0; i < specialTestCases.length; i++) {
failures += testSinhCaseWithUlpDiff(specialTestCases[i][0],
specialTestCases[i][1],
0.0);
}
// For powers of 2 less than 2^(-27), the second and
// subsequent terms of the Taylor series expansion will get
// rounded away since |n-n^3| > 53, the binary precision of a
// double significand.
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
double d = FpUtils.scalb(2.0, i);
// Result and expected are the same.
failures += testSinhCaseWithUlpDiff(d, d, 2.5);
}
// For values of x larger than 22, the e^(-x) term is
// insignificant to the floating-point result. Util exp(x)
// overflows around 709.8, sinh(x) ~= exp(x)/2; will will test
// 10000 values in this range.
long trans22 = Double.doubleToLongBits(22.0);
// (approximately) largest value such that exp shouldn't
// overflow
long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
for(long i = trans22;
i < transExpOvfl;
i +=(transExpOvfl-trans22)/10000) {
double d = Double.longBitsToDouble(i);
// Allow 3.5 ulps of error to deal with error in exp.
failures += testSinhCaseWithUlpDiff(d, StrictMath.exp(d)*0.5, 3.5);
}
// (approximately) largest value such that sinh shouldn't
// overflow.
long transSinhOvfl = Double.doubleToLongBits(710.4758600739439);
// Make sure sinh(x) doesn't overflow as soon as exp(x)
// overflows.
/*
* For large values of x, sinh(x) ~= 0.5*(e^x). Therefore,
*
* sinh(x) ~= e^(ln 0.5) * e^x = e^(x + ln 0.5)
*
* So, we can calculate the approximate expected result as
* exp(x + -0.693147186). However, this sum suffers from
* roundoff, limiting the accuracy of the approximation. The
* accuracy can be improved by recovering the rounded-off
* information. Since x is larger than ln(0.5), the trailing
* bits of ln(0.5) get rounded away when the two values are
* added. However, high-order bits of ln(0.5) that
* contribute to the sum can be found:
*
* offset = log(0.5);
* effective_offset = (x + offset) - x; // exact subtraction
* rounded_away_offset = offset - effective_offset; // exact subtraction
*
* Therefore, the product
*
* exp(x + offset)*exp(rounded_away_offset)
*
* will be a better approximation to the exact value of
*
* e^(x + offset)
*
* than exp(x+offset) alone. (The expected result cannot be
* computed as exp(x)*exp(offset) since exp(x) by itself would
* overflow to infinity.)
*/
double offset = StrictMath.log(0.5);
for(long i = transExpOvfl+1; i < transSinhOvfl;
i += (transSinhOvfl-transExpOvfl)/1000 ) {
double input = Double.longBitsToDouble(i);
double expected =
StrictMath.exp(input + offset) *
StrictMath.exp( offset - ((input + offset) - input) );
failures += testSinhCaseWithUlpDiff(input, expected, 4.0);
}
// sinh(x) overflows for values greater than 710; in
// particular, it overflows for all 2^i, i > 10.
for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
double d = FpUtils.scalb(2.0, i);
// Result and expected are the same.
failures += testSinhCaseWithUlpDiff(d,
Double.POSITIVE_INFINITY, 0.0);
}
return failures;
}
public static int testSinhCaseWithTolerance(double input,
double expected,
double tolerance) {
int failures = 0;
failures += Tests.testTolerance("Math.sinh(double)",
input, Math.sinh(input),
expected, tolerance);
failures += Tests.testTolerance("Math.sinh(double)",
-input, Math.sinh(-input),
-expected, tolerance);
failures += Tests.testTolerance("StrictMath.sinh(double)",
input, StrictMath.sinh(input),
expected, tolerance);
failures += Tests.testTolerance("StrictMath.sinh(double)",
-input, StrictMath.sinh(-input),
-expected, tolerance);
return failures;
}
public static int testSinhCaseWithUlpDiff(double input,
double expected,
double ulps) {
int failures = 0;
failures += Tests.testUlpDiff("Math.sinh(double)",
input, Math.sinh(input),
expected, ulps);
failures += Tests.testUlpDiff("Math.sinh(double)",
-input, Math.sinh(-input),
-expected, ulps);
failures += Tests.testUlpDiff("StrictMath.sinh(double)",
input, StrictMath.sinh(input),
expected, ulps);
failures += Tests.testUlpDiff("StrictMath.sinh(double)",
-input, StrictMath.sinh(-input),
-expected, ulps);
return failures;
}
/**
* Test accuracy of {Math, StrictMath}.cosh. The specified
* accuracy is 2.5 ulps.
*
* The defintion of cosh(x) is
*
* (e^x + e^(-x))/2
*
* The series expansion of cosh(x) =
*
* 1 + x^2/2! + x^4/4! + x^6/6! +...
*
* Therefore,
*
* 1. For large values of x cosh(x) ~= exp(|x|)/2
*
* 2. For small values of x, cosh(x) ~= 1.
*
* Additionally, cosh is an even function; cosh(-x) = cosh(x).
*
*/
static int testCosh() {
int failures = 0;
/*
* Array elements below generated using a quad cosh
* implementation. Rounded to a double, the quad result
* *should* be correctly rounded, unless we are quite unlucky.
* Assuming the quad value is a correctly rounded double, the
* allowed error is 3.0 ulps instead of 2.5 since the quad
* value rounded to double can have its own 1/2 ulp error.
*/
double [][] testCases = {
// x cosh(x)
{0.0625, 1.001953760865667607841550709632597376},
{0.1250, 1.007822677825710859846949685520422223},
{0.1875, 1.017629683800690526835115759894757615},
{0.2500, 1.031413099879573176159295417520378622},
{0.3125, 1.049226785060219076999158096606305793},
{0.3750, 1.071140346704586767299498015567016002},
{0.4375, 1.097239412531012567673453832328262160},
{0.5000, 1.127625965206380785226225161402672030},
{0.5625, 1.162418740845610783505338363214045218},
{0.6250, 1.201753692975606324229229064105075301},
{0.6875, 1.245784523776616395403056980542275175},
{0.7500, 1.294683284676844687841708185390181730},
{0.8125, 1.348641048647144208352285714214372703},
{0.8750, 1.407868656822803158638471458026344506},
{0.9375, 1.472597542369862933336886403008640891},
{1.0000, 1.543080634815243778477905620757061497},
{1.0625, 1.619593348374367728682469968448090763},
{1.1250, 1.702434658138190487400868008124755757},
{1.1875, 1.791928268324866464246665745956119612},
{1.2500, 1.888423877161015738227715728160051696},
{1.3125, 1.992298543335143985091891077551921106},
{1.3750, 2.103958159362661802010972984204389619},
{1.4375, 2.223839037619709260803023946704272699},
{1.5000, 2.352409615243247325767667965441644201},
{1.5625, 2.490172284559350293104864895029231913},
{1.6250, 2.637665356192137582275019088061812951},
{1.6875, 2.795465162524235691253423614360562624},
{1.7500, 2.964188309728087781773608481754531801},
{1.8125, 3.144494087167972176411236052303565201},
{1.8750, 3.337087043587520514308832278928116525},
{1.9375, 3.542719740149244276729383650503145346},
{2.0000, 3.762195691083631459562213477773746099},
{2.0625, 3.996372503438463642260225717607554880},
{2.1250, 4.246165228196992140600291052990934410},
{2.1875, 4.512549935859540340856119781585096760},
{2.2500, 4.796567530460195028666793366876218854},
{2.3125, 5.099327816921939817643745917141739051},
{2.3750, 5.422013837643509250646323138888569746},
{2.4375, 5.765886495263270945949271410819116399},
{2.5000, 6.132289479663686116619852312817562517},
{2.5625, 6.522654518468725462969589397439224177},
{2.6250, 6.938506971550673190999796241172117288},
{2.6875, 7.381471791406976069645686221095397137},
{2.7500, 7.853279872697439591457564035857305647},
{2.8125, 8.355774815752725814638234943192709129},
{2.8750, 8.890920130482709321824793617157134961},
{2.9375, 9.460806908834119747071078865866737196},
{3.0000, 10.067661995777765841953936035115890343},
{3.0625, 10.713856690753651225304006562698007312},
{3.1250, 11.401916013575067700373788969458446177},
{3.1875, 12.134528570998387744547733730974713055},
{3.2500, 12.914557062512392049483503752322408761},
{3.3125, 13.745049466398732213877084541992751273},
{3.3750, 14.629250949773302934853381428660210721},
{3.4375, 15.570616549147269180921654324879141947},
{3.5000, 16.572824671057316125696517821376119469},
{3.5625, 17.639791465519127930722105721028711044},
{3.6250, 18.775686128468677200079039891415789429},
{3.6875, 19.984947192985946987799359614758598457},
{3.7500, 21.272299872959396081877161903352144126},
{3.8125, 22.642774526961913363958587775566619798},
{3.8750, 24.101726314486257781049388094955970560},
{3.9375, 25.654856121347151067170940701379544221},
{4.0000, 27.308232836016486629201989612067059978},
{4.0625, 29.068317063936918520135334110824828950},
{4.1250, 30.941986372478026192360480044849306606},
{4.1875, 32.936562165180269851350626768308756303},
{4.2500, 35.059838290298428678502583470475012235},
{4.3125, 37.320111495433027109832850313172338419},
{4.3750, 39.726213847251883288518263854094284091},
{4.4375, 42.287547242982546165696077854963452084},
{4.5000, 45.014120148530027928305799939930642658},
{4.5625, 47.916586706774825161786212701923307169},
{4.6250, 51.006288368867753140854830589583165950},
{4.6875, 54.295298211196782516984520211780624960},
{4.7500, 57.796468111195389383795669320243166117},
{4.8125, 61.523478966332915041549750463563672435},
{4.8750, 65.490894152518731617237739112888213645},
{4.9375, 69.714216430810089539924900313140922323},
{5.0000, 74.209948524787844444106108044487704798},
{5.0625, 78.995657605307475581204965926043112946},
{5.1250, 84.090043934600961683400343038519519678},
{5.1875, 89.513013937957834087706670952561002466},
{5.2500, 95.285757988514588780586084642381131013},
{5.3125, 101.430833209098212357990123684449846912},
{5.3750, 107.972251614673824873137995865940755392},
{5.4375, 114.935573939814969189535554289886848550},
{5.5000, 122.348009517829425991091207107262038316},
{5.5625, 130.238522601820409078244923165746295574},
{5.6250, 138.637945543134998069351279801575968875},
{5.6875, 147.579099269447055276899288971207106581},
{5.7500, 157.096921533245353905868840194264636395},
{5.8125, 167.228603431860671946045256541679445836},
{5.8750, 178.013734732486824390148614309727161925},
{5.9375, 189.494458570056311567917444025807275896},
{6.0000, 201.715636122455894483405112855409538488},
{6.0625, 214.725021906554080628430756558271312513},
{6.1250, 228.573450380013557089736092321068279231},
{6.1875, 243.315034578039208138752165587134488645},
{6.2500, 259.007377561239126824465367865430519592},
{6.3125, 275.711797500835732516530131577254654076},
{6.3750, 293.493567280752348242602902925987643443},
{6.4375, 312.422169552825597994104814531010579387},
{6.5000, 332.571568241777409133204438572983297292},
{6.5625, 354.020497560858198165985214519757890505},
{6.6250, 376.852769667496146326030849450983914197},
{6.6875, 401.157602161123700280816957271992998156},
{6.7500, 427.029966702886171977469256622451185850},
{6.8125, 454.570960119471524953536004647195906721},
{6.8750, 483.888199441157626584508920036981010995},
{6.9375, 515.096242417696720610477570797503766179},
{7.0000, 548.317035155212076889964120712102928484},
{7.0625, 583.680388623257719787307547662358502345},
{7.1250, 621.324485894002926216918634755431456031},
{7.1875, 661.396422095589629755266517362992812037},
{7.2500, 704.052779189542208784574955807004218856},
{7.3125, 749.460237818184878095966335081928645934},
{7.3750, 797.796228612873763671070863694973560629},
{7.4375, 849.249625508044731271830060572510241864},
{7.5000, 904.021483770216677368692292389446994987},
{7.5625, 962.325825625814651122171697031114091993},
{7.6250, 1024.390476557670599008492465853663578558},
{7.6875, 1090.457955538048482588540574008226583335},
{7.7500, 1160.786422676798661020094043586456606003},
{7.8125, 1235.650687987597295222707689125107720568},
{7.8750, 1315.343285214046776004329388551335841550},
{7.9375, 1400.175614911635999247504386054087931958},
{8.0000, 1490.479161252178088627715460421007179728},
{8.0625, 1586.606787305415349050508956232945539108},
{8.1250, 1688.934113859132470361718199038326340668},
{8.1875, 1797.860987165547537276364148450577336075},
{8.2500, 1913.813041349231764486365114317586148767},
{8.3125, 2037.243361581700856522236313401822532385},
{8.3750, 2168.634254521568851112005905503069409349},
{8.4375, 2308.499132938297821208734949028296170563},
{8.5000, 2457.384521883751693037774022640629666294},
{8.5625, 2615.872194250713123494312356053193077854},
{8.6250, 2784.581444063104750127653362960649823247},
{8.6875, 2964.171506380845754878370650565756538203},
{8.7500, 3155.344133275174556354775488913749659006},
{8.8125, 3358.846335940117183452010789979584950102},
{8.8750, 3575.473303654961482727206202358956274888},
{8.9375, 3806.071511003646460448021740303914939059},
{9.0000, 4051.542025492594047194773093534725371440},
{9.0625, 4312.844028491571841588188869958240355518},
{9.1250, 4590.998563255739769060078863130940205710},
{9.1875, 4887.092524674358252509551443117048351290},
{9.2500, 5202.282906336187674588222835339193136030},
{9.3125, 5537.801321507079474415176386655744387251},
{9.3750, 5894.958815685577062811620236195525504885},
{9.4375, 6275.150989541692149890530417987358096221},
{9.5000, 6679.863452256851081801173722051940058824},
{9.5625, 7110.677626574055535297758456126491707647},
{9.6250, 7569.276928241617224537226019600213961572},
{9.6875, 8057.453343996777301036241026375049070162},
{9.7500, 8577.114433792824387959788368429252257664},
{9.8125, 9130.290784631065880205118262838330689429},
{9.8750, 9719.143945123662919857326995631317996715},
{9.9375, 10345.974871791805753327922796701684092861},
{10.0000, 11013.232920103323139721376090437880844591},
};
for(int i = 0; i < testCases.length; i++) {
double [] testCase = testCases[i];
failures += testCoshCaseWithUlpDiff(testCase[0],
testCase[1],
3.0);
}
double [][] specialTestCases = {
{0.0, 1.0},
{NaNd, NaNd},
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}
};
for(int i = 0; i < specialTestCases.length; i++ ) {
failures += testCoshCaseWithUlpDiff(specialTestCases[i][0],
specialTestCases[i][1],
0.0);
}
// For powers of 2 less than 2^(-27), the second and
// subsequent terms of the Taylor series expansion will get
// rounded.
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
double d = FpUtils.scalb(2.0, i);
// Result and expected are the same.
failures += testCoshCaseWithUlpDiff(d, 1.0, 2.5);
}
// For values of x larger than 22, the e^(-x) term is
// insignificant to the floating-point result. Util exp(x)
// overflows around 709.8, cosh(x) ~= exp(x)/2; will will test
// 10000 values in this range.
long trans22 = Double.doubleToLongBits(22.0);
// (approximately) largest value such that exp shouldn't
// overflow
long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
for(long i = trans22;
i < transExpOvfl;
i +=(transExpOvfl-trans22)/10000) {
double d = Double.longBitsToDouble(i);
// Allow 3.5 ulps of error to deal with error in exp.
failures += testCoshCaseWithUlpDiff(d, StrictMath.exp(d)*0.5, 3.5);
}
// (approximately) largest value such that cosh shouldn't
// overflow.
long transCoshOvfl = Double.doubleToLongBits(710.4758600739439);
// Make sure sinh(x) doesn't overflow as soon as exp(x)
// overflows.
/*
* For large values of x, cosh(x) ~= 0.5*(e^x). Therefore,
*
* cosh(x) ~= e^(ln 0.5) * e^x = e^(x + ln 0.5)
*
* So, we can calculate the approximate expected result as
* exp(x + -0.693147186). However, this sum suffers from
* roundoff, limiting the accuracy of the approximation. The
* accuracy can be improved by recovering the rounded-off
* information. Since x is larger than ln(0.5), the trailing
* bits of ln(0.5) get rounded away when the two values are
* added. However, high-order bits of ln(0.5) that
* contribute to the sum can be found:
*
* offset = log(0.5);
* effective_offset = (x + offset) - x; // exact subtraction
* rounded_away_offset = offset - effective_offset; // exact subtraction
*
* Therefore, the product
*
* exp(x + offset)*exp(rounded_away_offset)
*
* will be a better approximation to the exact value of
*
* e^(x + offset)
*
* than exp(x+offset) alone. (The expected result cannot be
* computed as exp(x)*exp(offset) since exp(x) by itself would
* overflow to infinity.)
*/
double offset = StrictMath.log(0.5);
for(long i = transExpOvfl+1; i < transCoshOvfl;
i += (transCoshOvfl-transExpOvfl)/1000 ) {
double input = Double.longBitsToDouble(i);
double expected =
StrictMath.exp(input + offset) *
StrictMath.exp( offset - ((input + offset) - input) );
failures += testCoshCaseWithUlpDiff(input, expected, 4.0);
}
// cosh(x) overflows for values greater than 710; in
// particular, it overflows for all 2^i, i > 10.
for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
double d = FpUtils.scalb(2.0, i);
// Result and expected are the same.
failures += testCoshCaseWithUlpDiff(d,
Double.POSITIVE_INFINITY, 0.0);
}
return failures;
}
public static int testCoshCaseWithTolerance(double input,
double expected,
double tolerance) {
int failures = 0;
failures += Tests.testTolerance("Math.cosh(double)",
input, Math.cosh(input),
expected, tolerance);
failures += Tests.testTolerance("Math.cosh(double)",
-input, Math.cosh(-input),
expected, tolerance);
failures += Tests.testTolerance("StrictMath.cosh(double)",
input, StrictMath.cosh(input),
expected, tolerance);
failures += Tests.testTolerance("StrictMath.cosh(double)",
-input, StrictMath.cosh(-input),
expected, tolerance);
return failures;
}
public static int testCoshCaseWithUlpDiff(double input,
double expected,
double ulps) {
int failures = 0;
failures += Tests.testUlpDiff("Math.cosh(double)",
input, Math.cosh(input),
expected, ulps);
failures += Tests.testUlpDiff("Math.cosh(double)",
-input, Math.cosh(-input),
expected, ulps);
failures += Tests.testUlpDiff("StrictMath.cosh(double)",
input, StrictMath.cosh(input),
expected, ulps);
failures += Tests.testUlpDiff("StrictMath.cosh(double)",
-input, StrictMath.cosh(-input),
expected, ulps);
return failures;
}
/**
* Test accuracy of {Math, StrictMath}.tanh. The specified
* accuracy is 2.5 ulps.
*
* The defintion of tanh(x) is
*
* (e^x - e^(-x))/(e^x + e^(-x))
*
* The series expansion of tanh(x) =
*
* x - x^3/3 + 2x^5/15 - 17x^7/315 + ...
*
* Therefore,
*
* 1. For large values of x tanh(x) ~= signum(x)
*
* 2. For small values of x, tanh(x) ~= x.
*
* Additionally, tanh is an odd function; tanh(-x) = -tanh(x).
*
*/
static int testTanh() {
int failures = 0;
/*
* Array elements below generated using a quad sinh
* implementation. Rounded to a double, the quad result
* *should* be correctly rounded, unless we are quite unlucky.
* Assuming the quad value is a correctly rounded double, the
* allowed error is 3.0 ulps instead of 2.5 since the quad
* value rounded to double can have its own 1/2 ulp error.
*/
double [][] testCases = {
// x tanh(x)
{0.0625, 0.06241874674751251449014289119421133},
{0.1250, 0.12435300177159620805464727580589271},
{0.1875, 0.18533319990813951753211997502482787},
{0.2500, 0.24491866240370912927780113149101697},
{0.3125, 0.30270972933210848724239738970991712},
{0.3750, 0.35835739835078594631936023155315807},
{0.4375, 0.41157005567402245143207555859415687},
{0.5000, 0.46211715726000975850231848364367256},
{0.5625, 0.50982997373525658248931213507053130},
{0.6250, 0.55459972234938229399903909532308371},
{0.6875, 0.59637355547924233984437303950726939},
{0.7500, 0.63514895238728731921443435731249638},
{0.8125, 0.67096707420687367394810954721913358},
{0.8750, 0.70390560393662106058763026963135371},
{0.9375, 0.73407151960434149263991588052503660},
{1.0000, 0.76159415595576488811945828260479366},
{1.0625, 0.78661881210869761781941794647736081},
{1.1250, 0.80930107020178101206077047354332696},
{1.1875, 0.82980190998595952708572559629034476},
{1.2500, 0.84828363995751289761338764670750445},
{1.3125, 0.86490661772074179125443141102709751},
{1.3750, 0.87982669965198475596055310881018259},
{1.4375, 0.89319334040035153149249598745889365},
{1.5000, 0.90514825364486643824230369645649557},
{1.5625, 0.91582454416876231820084311814416443},
{1.6250, 0.92534622531174107960457166792300374},
{1.6875, 0.93382804322259173763570528576138652},
{1.7500, 0.94137553849728736226942088377163687},
{1.8125, 0.94808528560440629971240651310180052},
{1.8750, 0.95404526017994877009219222661968285},
{1.9375, 0.95933529331468249183399461756952555},
{2.0000, 0.96402758007581688394641372410092317},
{2.0625, 0.96818721657637057702714316097855370},
{2.1250, 0.97187274591350905151254495374870401},
{2.1875, 0.97513669829362836159665586901156483},
{2.2500, 0.97802611473881363992272924300618321},
{2.3125, 0.98058304703705186541999427134482061},
{2.3750, 0.98284502917257603002353801620158861},
{2.4375, 0.98484551746427837912703608465407824},
{2.5000, 0.98661429815143028888127603923734964},
{2.5625, 0.98817786228751240824802592958012269},
{2.6250, 0.98955974861288320579361709496051109},
{2.6875, 0.99078085564125158320311117560719312},
{2.7500, 0.99185972456820774534967078914285035},
{2.8125, 0.99281279483715982021711715899682324},
{2.8750, 0.99365463431502962099607366282699651},
{2.9375, 0.99439814606575805343721743822723671},
{3.0000, 0.99505475368673045133188018525548849},
{3.0625, 0.99563456710930963835715538507891736},
{3.1250, 0.99614653067334504917102591131792951},
{3.1875, 0.99659855517712942451966113109487039},
{3.2500, 0.99699763548652601693227592643957226},
{3.3125, 0.99734995516557367804571991063376923},
{3.3750, 0.99766097946988897037219469409451602},
{3.4375, 0.99793553792649036103161966894686844},
{3.5000, 0.99817789761119870928427335245061171},
{3.5625, 0.99839182812874152902001617480606320},
{3.6250, 0.99858065920179882368897879066418294},
{3.6875, 0.99874733168378115962760304582965538},
{3.7500, 0.99889444272615280096784208280487888},
{3.8125, 0.99902428575443546808677966295308778},
{3.8750, 0.99913888583735077016137617231569011},
{3.9375, 0.99924003097049627100651907919688313},
{4.0000, 0.99932929973906704379224334434172499},
{4.0625, 0.99940808577297384603818654530731215},
{4.1250, 0.99947761936180856115470576756499454},
{4.1875, 0.99953898655601372055527046497863955},
{4.2500, 0.99959314604388958696521068958989891},
{4.3125, 0.99964094406130644525586201091350343},
{4.3750, 0.99968312756179494813069349082306235},
{4.4375, 0.99972035584870534179601447812936151},
{4.5000, 0.99975321084802753654050617379050162},
{4.5625, 0.99978220617994689112771768489030236},
{4.6250, 0.99980779516900105210240981251048167},
{4.6875, 0.99983037791655283849546303868853396},
{4.7500, 0.99985030754497877753787358852000255},
{4.8125, 0.99986789571029070417475400133989992},
{4.8750, 0.99988341746867772271011794614780441},
{4.9375, 0.99989711557251558205051185882773206},
{5.0000, 0.99990920426259513121099044753447306},
{5.0625, 0.99991987261554158551063867262784721},
{5.1250, 0.99992928749851651137225712249720606},
{5.1875, 0.99993759617721206697530526661105307},
{5.2500, 0.99994492861777083305830639416802036},
{5.3125, 0.99995139951851344080105352145538345},
{5.3750, 0.99995711010315817210152906092289064},
{5.4375, 0.99996214970350792531554669737676253},
{5.5000, 0.99996659715630380963848952941756868},
{5.5625, 0.99997052203605101013786592945475432},
{5.6250, 0.99997398574306704793434088941484766},
{5.6875, 0.99997704246374583929961850444364696},
{5.7500, 0.99997974001803825215761760428815437},
{5.8125, 0.99998212060739040166557477723121777},
{5.8750, 0.99998422147482750993344503195672517},
{5.9375, 0.99998607548749972326220227464612338},
{6.0000, 0.99998771165079557056434885235523206},
{6.0625, 0.99998915556205996764518917496149338},
{6.1250, 0.99999042981101021976277974520745310},
{6.1875, 0.99999155433311068015449574811497719},
{6.2500, 0.99999254672143162687722782398104276},
{6.3125, 0.99999342250186907900400800240980139},
{6.3750, 0.99999419537602957780612639767025158},
{6.4375, 0.99999487743557848265406225515388994},
{6.5000, 0.99999547935140419285107893831698753},
{6.5625, 0.99999601054055694588617385671796346},
{6.6250, 0.99999647931357331502887600387959900},
{6.6875, 0.99999689300449080997594368612277442},
{6.7500, 0.99999725808558628431084200832778748},
{6.8125, 0.99999758026863294516387464046135924},
{6.8750, 0.99999786459425991170635407313276785},
{6.9375, 0.99999811551081218572759991597586905},
{7.0000, 0.99999833694394467173571641595066708},
{7.0625, 0.99999853235803894918375164252059190},
{7.1250, 0.99999870481040359014665019356422927},
{7.1875, 0.99999885699910593255108365463415411},
{7.2500, 0.99999899130518359709674536482047025},
{7.3125, 0.99999910982989611769943303422227663},
{7.3750, 0.99999921442759946591163427422888252},
{7.4375, 0.99999930673475777603853435094943258},
{7.5000, 0.99999938819554614875054970643513124},
{7.5625, 0.99999946008444508183970109263856958},
{7.6250, 0.99999952352618001331402589096040117},
{7.6875, 0.99999957951331792817413683491979752},
{7.7500, 0.99999962892179632633374697389145081},
{7.8125, 0.99999967252462750190604116210421169},
{7.8750, 0.99999971100399253750324718031574484},
{7.9375, 0.99999974496191422474977283863588658},
{8.0000, 0.99999977492967588981001883295636840},
{8.0625, 0.99999980137613348259726597081723424},
{8.1250, 0.99999982471505097353529823063673263},
{8.1875, 0.99999984531157382142423402736529911},
{8.2500, 0.99999986348794179107425910499030547},
{8.3125, 0.99999987952853049895833839645847571},
{8.3750, 0.99999989368430056302584289932834041},
{8.4375, 0.99999990617672396471542088609051728},
{8.5000, 0.99999991720124905211338798152800748},
{8.5625, 0.99999992693035839516545287745322387},
{8.6250, 0.99999993551626733394129009365703767},
{8.6875, 0.99999994309330543951799157347876934},
{8.7500, 0.99999994978001814614368429416607424},
{8.8125, 0.99999995568102143535399207289008504},
{8.8750, 0.99999996088863858914831986187674522},
{8.9375, 0.99999996548434461974481685677429908},
{9.0000, 0.99999996954004097447930211118358244},
{9.0625, 0.99999997311918045901919121395899372},
{9.1250, 0.99999997627775997868467948564005257},
{9.1875, 0.99999997906519662964368381583648379},
{9.2500, 0.99999998152510084671976114264303159},
{9.3125, 0.99999998369595870397054673668361266},
{9.3750, 0.99999998561173404286033236040150950},
{9.4375, 0.99999998730239984852716512979473289},
{9.5000, 0.99999998879440718770812040917618843},
{9.5625, 0.99999999011109904501789298212541698},
{9.6250, 0.99999999127307553219220251303121960},
{9.6875, 0.99999999229851618412119275358396363},
{9.7500, 0.99999999320346438410630581726217930},
{9.8125, 0.99999999400207836827291739324060736},
{9.8750, 0.99999999470685273619047001387577653},
{9.9375, 0.99999999532881393331131526966058758},
{10.0000, 0.99999999587769276361959283713827574},
};
for(int i = 0; i < testCases.length; i++) {
double [] testCase = testCases[i];
failures += testTanhCaseWithUlpDiff(testCase[0],
testCase[1],
3.0);
}
double [][] specialTestCases = {
{0.0, 0.0},
{NaNd, NaNd},
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
{Double.POSITIVE_INFINITY, 1.0}
};
for(int i = 0; i < specialTestCases.length; i++) {
failures += testTanhCaseWithUlpDiff(specialTestCases[i][0],
specialTestCases[i][1],
0.0);
}
// For powers of 2 less than 2^(-27), the second and
// subsequent terms of the Taylor series expansion will get
// rounded away since |n-n^3| > 53, the binary precision of a
// double significand.
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
double d = FpUtils.scalb(2.0, i);
// Result and expected are the same.
failures += testTanhCaseWithUlpDiff(d, d, 2.5);
}
// For values of x larger than 22, tanh(x) is 1.0 in double
// floating-point arithmetic.
for(int i = 22; i < 32; i++) {
failures += testTanhCaseWithUlpDiff(i, 1.0, 2.5);
}
for(int i = 5; i <= DoubleConsts.MAX_EXPONENT; i++) {
double d = FpUtils.scalb(2.0, i);
failures += testTanhCaseWithUlpDiff(d, 1.0, 2.5);
}
return failures;
}
public static int testTanhCaseWithTolerance(double input,
double expected,
double tolerance) {
int failures = 0;
failures += Tests.testTolerance("Math.tanh(double",
input, Math.tanh(input),
expected, tolerance);
failures += Tests.testTolerance("Math.tanh(double",
-input, Math.tanh(-input),
-expected, tolerance);
failures += Tests.testTolerance("StrictMath.tanh(double",
input, StrictMath.tanh(input),
expected, tolerance);
failures += Tests.testTolerance("StrictMath.tanh(double",
-input, StrictMath.tanh(-input),
-expected, tolerance);
return failures;
}
public static int testTanhCaseWithUlpDiff(double input,
double expected,
double ulps) {
int failures = 0;
failures += Tests.testUlpDiffWithAbsBound("Math.tanh(double)",
input, Math.tanh(input),
expected, ulps, 1.0);
failures += Tests.testUlpDiffWithAbsBound("Math.tanh(double)",
-input, Math.tanh(-input),
-expected, ulps, 1.0);
failures += Tests.testUlpDiffWithAbsBound("StrictMath.tanh(double)",
input, StrictMath.tanh(input),
expected, ulps, 1.0);
failures += Tests.testUlpDiffWithAbsBound("StrictMath.tanh(double)",
-input, StrictMath.tanh(-input),
-expected, ulps, 1.0);
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += testSinh();
failures += testCosh();
failures += testTanh();
if (failures > 0) {
System.err.println("Testing the hyperbolic functions incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851638 4939441
* @summary Tests for {Math, StrictMath}.hypot
* @author Joseph D. Darcy
*/
import sun.misc.DoubleConsts;
import sun.misc.FpUtils;
public class HypotTests {
private HypotTests(){}
static final double infinityD = Double.POSITIVE_INFINITY;
static final double NaNd = Double.NaN;
/**
* Given integers m and n, assuming m < n, the triple (n^2 - m^2,
* 2mn, and n^2 + m^2) is a Pythagorean triple with a^2 + b^2 =
* c^2. This methods returns a long array holding the Pythagorean
* triple corresponding to the inputs.
*/
static long [] pythagoreanTriple(int m, int n) {
long M = m;
long N = n;
long result[] = new long[3];
result[0] = Math.abs(M*M - N*N);
result[1] = Math.abs(2*M*N);
result[2] = Math.abs(M*M + N*N);
return result;
}
static int testHypot() {
int failures = 0;
double [][] testCases = {
// Special cases
{infinityD, infinityD, infinityD},
{infinityD, 0.0, infinityD},
{infinityD, 1.0, infinityD},
{infinityD, NaNd, infinityD},
{NaNd, NaNd, NaNd},
{0.0, NaNd, NaNd},
{1.0, NaNd, NaNd},
{Double.longBitsToDouble(0x7FF0000000000001L), 1.0, NaNd},
{Double.longBitsToDouble(0xFFF0000000000001L), 1.0, NaNd},
{Double.longBitsToDouble(0x7FF8555555555555L), 1.0, NaNd},
{Double.longBitsToDouble(0xFFF8555555555555L), 1.0, NaNd},
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), 1.0, NaNd},
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), 1.0, NaNd},
{Double.longBitsToDouble(0x7FFDeadBeef00000L), 1.0, NaNd},
{Double.longBitsToDouble(0xFFFDeadBeef00000L), 1.0, NaNd},
{Double.longBitsToDouble(0x7FFCafeBabe00000L), 1.0, NaNd},
{Double.longBitsToDouble(0xFFFCafeBabe00000L), 1.0, NaNd},
};
for(int i = 0; i < testCases.length; i++) {
failures += testHypotCase(testCases[i][0], testCases[i][1],
testCases[i][2]);
}
// Verify hypot(x, 0.0) is close to x over the entire exponent
// range.
for(int i = DoubleConsts.MIN_SUB_EXPONENT;
i <= DoubleConsts.MAX_EXPONENT;
i++) {
double input = FpUtils.scalb(2, i);
failures += testHypotCase(input, 0.0, input);
}
// Test Pythagorean triples
// Small ones
for(int m = 1; m < 10; m++) {
for(int n = m+1; n < 11; n++) {
long [] result = pythagoreanTriple(m, n);
failures += testHypotCase(result[0], result[1], result[2]);
}
}
// Big ones
for(int m = 100000; m < 100100; m++) {
for(int n = m+100000; n < 200200; n++) {
long [] result = pythagoreanTriple(m, n);
failures += testHypotCase(result[0], result[1], result[2]);
}
}
// Approaching overflow tests
/*
* Create a random value r with an large-ish exponent. The
* result of hypot(3*r, 4*r) should be approximately 5*r. (The
* computation of 4*r is exact since it just changes the
* exponent). While the exponent of r is less than or equal
* to (MAX_EXPONENT - 3), the computation should not overflow.
*/
java.util.Random rand = new java.util.Random();
for(int i = 0; i < 1000; i++) {
double d = rand.nextDouble();
// Scale d to have an exponent equal to MAX_EXPONENT -15
d = FpUtils.scalb(d, DoubleConsts.MAX_EXPONENT
-15 - FpUtils.ilogb(d));
for(int j = 0; j <= 13; j += 1) {
failures += testHypotCase(3*d, 4*d, 5*d, 2.5);
d *= 2.0; // increase exponent by 1
}
}
// Test for monotonicity failures. Fix one argument and test
// two numbers before and two numbers after each chosen value;
// i.e.
//
// pcNeighbors[] =
// {nextDown(nextDown(pc)),
// nextDown(pc),
// pc,
// nextUp(pc),
// nextUp(nextUp(pc))}
//
// and we test that hypot(pcNeighbors[i]) <= hypot(pcNeighbors[i+1])
{
double pcNeighbors[] = new double[5];
double pcNeighborsHypot[] = new double[5];
double pcNeighborsStrictHypot[] = new double[5];
for(int i = -18; i <= 18; i++) {
double pc = FpUtils.scalb(1.0, i);
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[3] = FpUtils.nextUp(pc);
pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsHypot[j] = Math.hypot(2.0, pcNeighbors[j]);
pcNeighborsStrictHypot[j] = StrictMath.hypot(2.0, pcNeighbors[j]);
}
for(int j = 0; j < pcNeighborsHypot.length-1; j++) {
if(pcNeighborsHypot[j] > pcNeighborsHypot[j+1] ) {
failures++;
System.err.println("Monotonicity failure for Math.hypot on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsHypot[j] + " and " +
pcNeighborsHypot[j+1] );
}
if(pcNeighborsStrictHypot[j] > pcNeighborsStrictHypot[j+1] ) {
failures++;
System.err.println("Monotonicity failure for StrictMath.hypot on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsStrictHypot[j] + " and " +
pcNeighborsStrictHypot[j+1] );
}
}
}
}
return failures;
}
static int testHypotCase(double input1, double input2, double expected) {
return testHypotCase(input1,input2, expected, 1);
}
static int testHypotCase(double input1, double input2, double expected,
double ulps) {
int failures = 0;
if (expected < 0.0) {
throw new AssertionError("Result of hypot must be greater than " +
"or equal to zero");
}
// Test Math and StrictMath methods with no inputs negated,
// each input negated singly, and both inputs negated. Also
// test inputs in reversed order.
for(int i = -1; i <= 1; i+=2) {
for(int j = -1; j <= 1; j+=2) {
double x = i * input1;
double y = j * input2;
failures += Tests.testUlpDiff("Math.hypot", x, y,
Math.hypot(x, y), expected, ulps);
failures += Tests.testUlpDiff("Math.hypot", y, x,
Math.hypot(y, x ), expected, ulps);
failures += Tests.testUlpDiff("StrictMath.hypot", x, y,
StrictMath.hypot(x, y), expected, ulps);
failures += Tests.testUlpDiff("StrictMath.hypot", y, x,
StrictMath.hypot(y, x), expected, ulps);
}
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += testHypot();
if (failures > 0) {
System.err.println("Testing the hypot incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4860891 4826732 4780454 4939441 4826652
* @summary Tests for IEEE 754[R] recommended functions and similar methods
* @author Joseph D. Darcy
* @compile -source 1.5 IeeeRecommendedTests.java
* @run main IeeeRecommendedTests
*/
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
import sun.misc.FloatConsts;
public class IeeeRecommendedTests {
private IeeeRecommendedTests(){}
static final float NaNf = Float.NaN;
static final double NaNd = Double.NaN;
static final float infinityF = Float.POSITIVE_INFINITY;
static final double infinityD = Double.POSITIVE_INFINITY;
static final float Float_MAX_VALUEmm = 0x1.fffffcP+127f;
static final float Float_MAX_SUBNORMAL = 0x0.fffffeP-126f;
static final float Float_MAX_SUBNORMALmm = 0x0.fffffcP-126f;
static final double Double_MAX_VALUEmm = 0x1.ffffffffffffeP+1023;
static final double Double_MAX_SUBNORMAL = 0x0.fffffffffffffP-1022;
static final double Double_MAX_SUBNORMALmm = 0x0.ffffffffffffeP-1022;
// Initialize shared random number generator
static java.util.Random rand = new java.util.Random();
/**
* Returns a floating-point power of two in the normal range.
*/
static double powerOfTwoD(int n) {
return Double.longBitsToDouble((((long)n + (long)DoubleConsts.MAX_EXPONENT) <<
(DoubleConsts.SIGNIFICAND_WIDTH-1))
& DoubleConsts.EXP_BIT_MASK);
}
/**
* Returns a floating-point power of two in the normal range.
*/
static float powerOfTwoF(int n) {
return Float.intBitsToFloat(((n + FloatConsts.MAX_EXPONENT) <<
(FloatConsts.SIGNIFICAND_WIDTH-1))
& FloatConsts.EXP_BIT_MASK);
}
/* ******************** getExponent tests ****************************** */
/*
* The tests for getExponent should test the special values (NaN, +/-
* infinity, etc.), test the endpoints of each binade (set of
* floating-point values with the same exponent), and for good
* measure, test some random values within each binade. Testing
* the endpoints of each binade includes testing both positive and
* negative numbers. Subnormal values with different normalized
* exponents should be tested too. Both Math and StrictMath
* methods should return the same results.
*/
/*
* Test Math.getExponent and StrictMath.getExponent with +d and -d.
*/
static int testGetExponentCase(float f, int expected) {
float minus_f = -f;
int failures=0;
failures+=Tests.test("Math.getExponent(float)", f,
Math.getExponent(f), expected);
failures+=Tests.test("Math.getExponent(float)", minus_f,
Math.getExponent(minus_f), expected);
failures+=Tests.test("StrictMath.getExponent(float)", f,
StrictMath.getExponent(f), expected);
failures+=Tests.test("StrictMath.getExponent(float)", minus_f,
StrictMath.getExponent(minus_f), expected);
return failures;
}
/*
* Test Math.getExponent and StrictMath.getExponent with +d and -d.
*/
static int testGetExponentCase(double d, int expected) {
double minus_d = -d;
int failures=0;
failures+=Tests.test("Math.getExponent(double)", d,
Math.getExponent(d), expected);
failures+=Tests.test("Math.getExponent(double)", minus_d,
Math.getExponent(minus_d), expected);
failures+=Tests.test("StrictMath.getExponent(double)", d,
StrictMath.getExponent(d), expected);
failures+=Tests.test("StrictMath.getExponent(double)", minus_d,
StrictMath.getExponent(minus_d), expected);
return failures;
}
public static int testFloatGetExponent() {
int failures = 0;
float [] specialValues = {NaNf,
Float.POSITIVE_INFINITY,
+0.0f,
+1.0f,
+2.0f,
+16.0f,
+Float.MIN_VALUE,
+Float_MAX_SUBNORMAL,
+FloatConsts.MIN_NORMAL,
+Float.MAX_VALUE
};
int [] specialResults = {Float.MAX_EXPONENT + 1, // NaN results
Float.MAX_EXPONENT + 1, // Infinite results
Float.MIN_EXPONENT - 1, // Zero results
0,
1,
4,
FloatConsts.MIN_EXPONENT - 1,
-FloatConsts.MAX_EXPONENT,
FloatConsts.MIN_EXPONENT,
FloatConsts.MAX_EXPONENT
};
// Special value tests
for(int i = 0; i < specialValues.length; i++) {
failures += testGetExponentCase(specialValues[i], specialResults[i]);
}
// Normal exponent tests
for(int i = FloatConsts.MIN_EXPONENT; i <= FloatConsts.MAX_EXPONENT; i++) {
int result;
// Create power of two
float po2 = powerOfTwoF(i);
failures += testGetExponentCase(po2, i);
// Generate some random bit patterns for the significand
for(int j = 0; j < 10; j++) {
int randSignif = rand.nextInt();
float randFloat;
randFloat = Float.intBitsToFloat( // Exponent
(Float.floatToIntBits(po2)&
(~FloatConsts.SIGNIF_BIT_MASK)) |
// Significand
(randSignif &
FloatConsts.SIGNIF_BIT_MASK) );
failures += testGetExponentCase(randFloat, i);
}
if (i > FloatConsts.MIN_EXPONENT) {
float po2minus = FpUtils.nextAfter(po2,
Float.NEGATIVE_INFINITY);
failures += testGetExponentCase(po2minus, i-1);
}
}
// Subnormal exponent tests
/*
* Start with MIN_VALUE, left shift, test high value, low
* values, and random in between.
*
* Use nextAfter to calculate, high value of previous binade,
* loop count i will indicate how many random bits, if any are
* needed.
*/
float top=Float.MIN_VALUE;
for( int i = 1;
i < FloatConsts.SIGNIFICAND_WIDTH;
i++, top *= 2.0f) {
failures += testGetExponentCase(top,
FloatConsts.MIN_EXPONENT - 1);
// Test largest value in next smaller binade
if (i >= 3) {// (i == 1) would test 0.0;
// (i == 2) would just retest MIN_VALUE
testGetExponentCase(FpUtils.nextAfter(top, 0.0f),
FloatConsts.MIN_EXPONENT - 1);
if( i >= 10) {
// create a bit mask with (i-1) 1's in the low order
// bits
int mask = ~((~0)<<(i-1));
float randFloat = Float.intBitsToFloat( // Exponent
Float.floatToIntBits(top) |
// Significand
(rand.nextInt() & mask ) ) ;
failures += testGetExponentCase(randFloat,
FloatConsts.MIN_EXPONENT - 1);
}
}
}
return failures;
}
public static int testDoubleGetExponent() {
int failures = 0;
double [] specialValues = {NaNd,
infinityD,
+0.0,
+1.0,
+2.0,
+16.0,
+Double.MIN_VALUE,
+Double_MAX_SUBNORMAL,
+DoubleConsts.MIN_NORMAL,
+Double.MAX_VALUE
};
int [] specialResults = {Double.MAX_EXPONENT + 1, // NaN results
Double.MAX_EXPONENT + 1, // Infinite results
Double.MIN_EXPONENT - 1, // Zero results
0,
1,
4,
DoubleConsts.MIN_EXPONENT - 1,
-DoubleConsts.MAX_EXPONENT,
DoubleConsts.MIN_EXPONENT,
DoubleConsts.MAX_EXPONENT
};
// Special value tests
for(int i = 0; i < specialValues.length; i++) {
failures += testGetExponentCase(specialValues[i], specialResults[i]);
}
// Normal exponent tests
for(int i = DoubleConsts.MIN_EXPONENT; i <= DoubleConsts.MAX_EXPONENT; i++) {
int result;
// Create power of two
double po2 = powerOfTwoD(i);
failures += testGetExponentCase(po2, i);
// Generate some random bit patterns for the significand
for(int j = 0; j < 10; j++) {
long randSignif = rand.nextLong();
double randFloat;
randFloat = Double.longBitsToDouble( // Exponent
(Double.doubleToLongBits(po2)&
(~DoubleConsts.SIGNIF_BIT_MASK)) |
// Significand
(randSignif &
DoubleConsts.SIGNIF_BIT_MASK) );
failures += testGetExponentCase(randFloat, i);
}
if (i > DoubleConsts.MIN_EXPONENT) {
double po2minus = FpUtils.nextAfter(po2,
Double.NEGATIVE_INFINITY);
failures += testGetExponentCase(po2minus, i-1);
}
}
// Subnormal exponent tests
/*
* Start with MIN_VALUE, left shift, test high value, low
* values, and random in between.
*
* Use nextAfter to calculate, high value of previous binade;
* loop count i will indicate how many random bits, if any are
* needed.
*/
double top=Double.MIN_VALUE;
for( int i = 1;
i < DoubleConsts.SIGNIFICAND_WIDTH;
i++, top *= 2.0f) {
failures += testGetExponentCase(top,
DoubleConsts.MIN_EXPONENT - 1);
// Test largest value in next smaller binade
if (i >= 3) {// (i == 1) would test 0.0;
// (i == 2) would just retest MIN_VALUE
testGetExponentCase(FpUtils.nextAfter(top, 0.0),
DoubleConsts.MIN_EXPONENT - 1);
if( i >= 10) {
// create a bit mask with (i-1) 1's in the low order
// bits
long mask = ~((~0L)<<(i-1));
double randFloat = Double.longBitsToDouble( // Exponent
Double.doubleToLongBits(top) |
// Significand
(rand.nextLong() & mask ) ) ;
failures += testGetExponentCase(randFloat,
DoubleConsts.MIN_EXPONENT - 1);
}
}
}
return failures;
}
/* ******************** nextAfter tests ****************************** */
static int testNextAfterCase(float start, double direction, float expected) {
int failures=0;
float minus_start = -start;
double minus_direction = -direction;
float minus_expected = -expected;
failures+=Tests.test("Math.nextAfter(float,double)", start, direction,
Math.nextAfter(start, direction), expected);
failures+=Tests.test("Math.nextAfter(float,double)", minus_start, minus_direction,
Math.nextAfter(minus_start, minus_direction), minus_expected);
failures+=Tests.test("StrictMath.nextAfter(float,double)", start, direction,
StrictMath.nextAfter(start, direction), expected);
failures+=Tests.test("StrictMath.nextAfter(float,double)", minus_start, minus_direction,
StrictMath.nextAfter(minus_start, minus_direction), minus_expected);
return failures;
}
static int testNextAfterCase(double start, double direction, double expected) {
int failures=0;
double minus_start = -start;
double minus_direction = -direction;
double minus_expected = -expected;
failures+=Tests.test("Math.nextAfter(double,double)", start, direction,
Math.nextAfter(start, direction), expected);
failures+=Tests.test("Math.nextAfter(double,double)", minus_start, minus_direction,
Math.nextAfter(minus_start, minus_direction), minus_expected);
failures+=Tests.test("StrictMath.nextAfter(double,double)", start, direction,
StrictMath.nextAfter(start, direction), expected);
failures+=Tests.test("StrictMath.nextAfter(double,double)", minus_start, minus_direction,
StrictMath.nextAfter(minus_start, minus_direction), minus_expected);
return failures;
}
public static int testFloatNextAfter() {
int failures=0;
/*
* Each row of the testCases matrix represents one test case
* for nexAfter; given the input of the first two columns, the
* result in the last column is expected.
*/
float [][] testCases = {
{NaNf, NaNf, NaNf},
{NaNf, 0.0f, NaNf},
{0.0f, NaNf, NaNf},
{NaNf, infinityF, NaNf},
{infinityF, NaNf, NaNf},
{infinityF, infinityF, infinityF},
{infinityF, -infinityF, Float.MAX_VALUE},
{infinityF, 0.0f, Float.MAX_VALUE},
{Float.MAX_VALUE, infinityF, infinityF},
{Float.MAX_VALUE, -infinityF, Float_MAX_VALUEmm},
{Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE},
{Float.MAX_VALUE, 0.0f, Float_MAX_VALUEmm},
{Float_MAX_VALUEmm, Float.MAX_VALUE, Float.MAX_VALUE},
{Float_MAX_VALUEmm, infinityF, Float.MAX_VALUE},
{Float_MAX_VALUEmm, Float_MAX_VALUEmm, Float_MAX_VALUEmm},
{FloatConsts.MIN_NORMAL, infinityF, FloatConsts.MIN_NORMAL+
Float.MIN_VALUE},
{FloatConsts.MIN_NORMAL, -infinityF, Float_MAX_SUBNORMAL},
{FloatConsts.MIN_NORMAL, 1.0f, FloatConsts.MIN_NORMAL+
Float.MIN_VALUE},
{FloatConsts.MIN_NORMAL, -1.0f, Float_MAX_SUBNORMAL},
{FloatConsts.MIN_NORMAL, FloatConsts.MIN_NORMAL, FloatConsts.MIN_NORMAL},
{Float_MAX_SUBNORMAL, FloatConsts.MIN_NORMAL, FloatConsts.MIN_NORMAL},
{Float_MAX_SUBNORMAL, Float_MAX_SUBNORMAL, Float_MAX_SUBNORMAL},
{Float_MAX_SUBNORMAL, 0.0f, Float_MAX_SUBNORMALmm},
{Float_MAX_SUBNORMALmm, Float_MAX_SUBNORMAL, Float_MAX_SUBNORMAL},
{Float_MAX_SUBNORMALmm, 0.0f, Float_MAX_SUBNORMALmm-Float.MIN_VALUE},
{Float_MAX_SUBNORMALmm, Float_MAX_SUBNORMALmm, Float_MAX_SUBNORMALmm},
{Float.MIN_VALUE, 0.0f, 0.0f},
{-Float.MIN_VALUE, 0.0f, -0.0f},
{Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE},
{Float.MIN_VALUE, 1.0f, 2*Float.MIN_VALUE},
// Make sure zero behavior is tested
{0.0f, 0.0f, 0.0f},
{0.0f, -0.0f, -0.0f},
{-0.0f, 0.0f, 0.0f},
{-0.0f, -0.0f, -0.0f},
{0.0f, infinityF, Float.MIN_VALUE},
{0.0f, -infinityF, -Float.MIN_VALUE},
{-0.0f, infinityF, Float.MIN_VALUE},
{-0.0f, -infinityF, -Float.MIN_VALUE},
{0.0f, Float.MIN_VALUE, Float.MIN_VALUE},
{0.0f, -Float.MIN_VALUE, -Float.MIN_VALUE},
{-0.0f, Float.MIN_VALUE, Float.MIN_VALUE},
{-0.0f, -Float.MIN_VALUE, -Float.MIN_VALUE}
};
for(int i = 0; i < testCases.length; i++) {
failures += testNextAfterCase(testCases[i][0], testCases[i][1],
testCases[i][2]);
}
return failures;
}
public static int testDoubleNextAfter() {
int failures =0;
/*
* Each row of the testCases matrix represents one test case
* for nexAfter; given the input of the first two columns, the
* result in the last column is expected.
*/
double [][] testCases = {
{NaNd, NaNd, NaNd},
{NaNd, 0.0d, NaNd},
{0.0d, NaNd, NaNd},
{NaNd, infinityD, NaNd},
{infinityD, NaNd, NaNd},
{infinityD, infinityD, infinityD},
{infinityD, -infinityD, Double.MAX_VALUE},
{infinityD, 0.0d, Double.MAX_VALUE},
{Double.MAX_VALUE, infinityD, infinityD},
{Double.MAX_VALUE, -infinityD, Double_MAX_VALUEmm},
{Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE},
{Double.MAX_VALUE, 0.0d, Double_MAX_VALUEmm},
{Double_MAX_VALUEmm, Double.MAX_VALUE, Double.MAX_VALUE},
{Double_MAX_VALUEmm, infinityD, Double.MAX_VALUE},
{Double_MAX_VALUEmm, Double_MAX_VALUEmm, Double_MAX_VALUEmm},
{DoubleConsts.MIN_NORMAL, infinityD, DoubleConsts.MIN_NORMAL+
Double.MIN_VALUE},
{DoubleConsts.MIN_NORMAL, -infinityD, Double_MAX_SUBNORMAL},
{DoubleConsts.MIN_NORMAL, 1.0f, DoubleConsts.MIN_NORMAL+
Double.MIN_VALUE},
{DoubleConsts.MIN_NORMAL, -1.0f, Double_MAX_SUBNORMAL},
{DoubleConsts.MIN_NORMAL, DoubleConsts.MIN_NORMAL,DoubleConsts.MIN_NORMAL},
{Double_MAX_SUBNORMAL, DoubleConsts.MIN_NORMAL,DoubleConsts.MIN_NORMAL},
{Double_MAX_SUBNORMAL, Double_MAX_SUBNORMAL, Double_MAX_SUBNORMAL},
{Double_MAX_SUBNORMAL, 0.0d, Double_MAX_SUBNORMALmm},
{Double_MAX_SUBNORMALmm, Double_MAX_SUBNORMAL, Double_MAX_SUBNORMAL},
{Double_MAX_SUBNORMALmm, 0.0d, Double_MAX_SUBNORMALmm-Double.MIN_VALUE},
{Double_MAX_SUBNORMALmm, Double_MAX_SUBNORMALmm, Double_MAX_SUBNORMALmm},
{Double.MIN_VALUE, 0.0d, 0.0d},
{-Double.MIN_VALUE, 0.0d, -0.0d},
{Double.MIN_VALUE, Double.MIN_VALUE, Double.MIN_VALUE},
{Double.MIN_VALUE, 1.0f, 2*Double.MIN_VALUE},
// Make sure zero behavior is tested
{0.0d, 0.0d, 0.0d},
{0.0d, -0.0d, -0.0d},
{-0.0d, 0.0d, 0.0d},
{-0.0d, -0.0d, -0.0d},
{0.0d, infinityD, Double.MIN_VALUE},
{0.0d, -infinityD, -Double.MIN_VALUE},
{-0.0d, infinityD, Double.MIN_VALUE},
{-0.0d, -infinityD, -Double.MIN_VALUE},
{0.0d, Double.MIN_VALUE, Double.MIN_VALUE},
{0.0d, -Double.MIN_VALUE, -Double.MIN_VALUE},
{-0.0d, Double.MIN_VALUE, Double.MIN_VALUE},
{-0.0d, -Double.MIN_VALUE, -Double.MIN_VALUE}
};
for(int i = 0; i < testCases.length; i++) {
failures += testNextAfterCase(testCases[i][0], testCases[i][1],
testCases[i][2]);
}
return failures;
}
/* ******************** nextUp tests ********************************* */
public static int testFloatNextUp() {
int failures=0;
/*
* Each row of testCases represents one test case for nextUp;
* the first column is the input and the second column is the
* expected result.
*/
float testCases [][] = {
{NaNf, NaNf},
{-infinityF, -Float.MAX_VALUE},
{-Float.MAX_VALUE, -Float_MAX_VALUEmm},
{-FloatConsts.MIN_NORMAL, -Float_MAX_SUBNORMAL},
{-Float_MAX_SUBNORMAL, -Float_MAX_SUBNORMALmm},
{-Float.MIN_VALUE, -0.0f},
{-0.0f, Float.MIN_VALUE},
{+0.0f, Float.MIN_VALUE},
{Float.MIN_VALUE, Float.MIN_VALUE*2},
{Float_MAX_SUBNORMALmm, Float_MAX_SUBNORMAL},
{Float_MAX_SUBNORMAL, FloatConsts.MIN_NORMAL},
{FloatConsts.MIN_NORMAL, FloatConsts.MIN_NORMAL+Float.MIN_VALUE},
{Float_MAX_VALUEmm, Float.MAX_VALUE},
{Float.MAX_VALUE, infinityF},
{infinityF, infinityF}
};
for(int i = 0; i < testCases.length; i++) {
failures+=Tests.test("Math.nextUp(float)",
testCases[i][0], Math.nextUp(testCases[i][0]), testCases[i][1]);
failures+=Tests.test("StrictMath.nextUp(float)",
testCases[i][0], StrictMath.nextUp(testCases[i][0]), testCases[i][1]);
}
return failures;
}
public static int testDoubleNextUp() {
int failures=0;
/*
* Each row of testCases represents one test case for nextUp;
* the first column is the input and the second column is the
* expected result.
*/
double testCases [][] = {
{NaNd, NaNd},
{-infinityD, -Double.MAX_VALUE},
{-Double.MAX_VALUE, -Double_MAX_VALUEmm},
{-DoubleConsts.MIN_NORMAL, -Double_MAX_SUBNORMAL},
{-Double_MAX_SUBNORMAL, -Double_MAX_SUBNORMALmm},
{-Double.MIN_VALUE, -0.0d},
{-0.0d, Double.MIN_VALUE},
{+0.0d, Double.MIN_VALUE},
{Double.MIN_VALUE, Double.MIN_VALUE*2},
{Double_MAX_SUBNORMALmm, Double_MAX_SUBNORMAL},
{Double_MAX_SUBNORMAL, DoubleConsts.MIN_NORMAL},
{DoubleConsts.MIN_NORMAL, DoubleConsts.MIN_NORMAL+Double.MIN_VALUE},
{Double_MAX_VALUEmm, Double.MAX_VALUE},
{Double.MAX_VALUE, infinityD},
{infinityD, infinityD}
};
for(int i = 0; i < testCases.length; i++) {
failures+=Tests.test("Math.nextUp(double)",
testCases[i][0], Math.nextUp(testCases[i][0]), testCases[i][1]);
failures+=Tests.test("StrictMath.nextUp(double)",
testCases[i][0], StrictMath.nextUp(testCases[i][0]), testCases[i][1]);
}
return failures;
}
/* ******************** nextDown tests ********************************* */
public static int testFloatNextDown() {
int failures=0;
/*
* Each row of testCases represents one test case for nextDown;
* the first column is the input and the second column is the
* expected result.
*/
float testCases [][] = {
{NaNf, NaNf},
{-infinityF, -infinityF},
{-Float.MAX_VALUE, -infinityF},
{-Float_MAX_VALUEmm, -Float.MAX_VALUE},
{-Float_MAX_SUBNORMAL, -FloatConsts.MIN_NORMAL},
{-Float_MAX_SUBNORMALmm, -Float_MAX_SUBNORMAL},
{-0.0f, -Float.MIN_VALUE},
{+0.0f, -Float.MIN_VALUE},
{Float.MIN_VALUE, 0.0f},
{Float.MIN_VALUE*2, Float.MIN_VALUE},
{Float_MAX_SUBNORMAL, Float_MAX_SUBNORMALmm},
{FloatConsts.MIN_NORMAL, Float_MAX_SUBNORMAL},
{FloatConsts.MIN_NORMAL+
Float.MIN_VALUE, FloatConsts.MIN_NORMAL},
{Float.MAX_VALUE, Float_MAX_VALUEmm},
{infinityF, Float.MAX_VALUE},
};
for(int i = 0; i < testCases.length; i++) {
failures+=Tests.test("FpUtils.nextDown(float)",
testCases[i][0], FpUtils.nextDown(testCases[i][0]), testCases[i][1]);
}
return failures;
}
public static int testDoubleNextDown() {
int failures=0;
/*
* Each row of testCases represents one test case for nextDown;
* the first column is the input and the second column is the
* expected result.
*/
double testCases [][] = {
{NaNd, NaNd},
{-infinityD, -infinityD},
{-Double.MAX_VALUE, -infinityD},
{-Double_MAX_VALUEmm, -Double.MAX_VALUE},
{-Double_MAX_SUBNORMAL, -DoubleConsts.MIN_NORMAL},
{-Double_MAX_SUBNORMALmm, -Double_MAX_SUBNORMAL},
{-0.0d, -Double.MIN_VALUE},
{+0.0d, -Double.MIN_VALUE},
{Double.MIN_VALUE, 0.0d},
{Double.MIN_VALUE*2, Double.MIN_VALUE},
{Double_MAX_SUBNORMAL, Double_MAX_SUBNORMALmm},
{DoubleConsts.MIN_NORMAL, Double_MAX_SUBNORMAL},
{DoubleConsts.MIN_NORMAL+
Double.MIN_VALUE, DoubleConsts.MIN_NORMAL},
{Double.MAX_VALUE, Double_MAX_VALUEmm},
{infinityD, Double.MAX_VALUE},
};
for(int i = 0; i < testCases.length; i++) {
failures+=Tests.test("FpUtils.nextDown(double)",
testCases[i][0], FpUtils.nextDown(testCases[i][0]), testCases[i][1]);
}
return failures;
}
/* ********************** boolean tests ****************************** */
/*
* Combined tests for boolean functions, isFinite, isInfinite,
* isNaN, isUnordered.
*/
public static int testFloatBooleanMethods() {
int failures = 0;
float testCases [] = {
NaNf,
-infinityF,
infinityF,
-Float.MAX_VALUE,
-3.0f,
-1.0f,
-FloatConsts.MIN_NORMAL,
-Float_MAX_SUBNORMALmm,
-Float_MAX_SUBNORMAL,
-Float.MIN_VALUE,
-0.0f,
+0.0f,
Float.MIN_VALUE,
Float_MAX_SUBNORMALmm,
Float_MAX_SUBNORMAL,
FloatConsts.MIN_NORMAL,
1.0f,
3.0f,
Float_MAX_VALUEmm,
Float.MAX_VALUE
};
for(int i = 0; i < testCases.length; i++) {
// isNaN
failures+=Tests.test("FpUtils.isNaN(float)", testCases[i],
FpUtils.isNaN(testCases[i]), (i ==0));
// isFinite
failures+=Tests.test("FpUtils.isFinite(float)", testCases[i],
FpUtils.isFinite(testCases[i]), (i >= 3));
// isInfinite
failures+=Tests.test("FpUtils.isInfinite(float)", testCases[i],
FpUtils.isInfinite(testCases[i]), (i==1 || i==2));
// isUnorderd
for(int j = 0; j < testCases.length; j++) {
failures+=Tests.test("FpUtils.isUnordered(float, float)", testCases[i],testCases[j],
FpUtils.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
}
}
return failures;
}
public static int testDoubleBooleanMethods() {
int failures = 0;
boolean result = false;
double testCases [] = {
NaNd,
-infinityD,
infinityD,
-Double.MAX_VALUE,
-3.0d,
-1.0d,
-DoubleConsts.MIN_NORMAL,
-Double_MAX_SUBNORMALmm,
-Double_MAX_SUBNORMAL,
-Double.MIN_VALUE,
-0.0d,
+0.0d,
Double.MIN_VALUE,
Double_MAX_SUBNORMALmm,
Double_MAX_SUBNORMAL,
DoubleConsts.MIN_NORMAL,
1.0d,
3.0d,
Double_MAX_VALUEmm,
Double.MAX_VALUE
};
for(int i = 0; i < testCases.length; i++) {
// isNaN
failures+=Tests.test("FpUtils.isNaN(double)", testCases[i],
FpUtils.isNaN(testCases[i]), (i ==0));
// isFinite
failures+=Tests.test("FpUtils.isFinite(double)", testCases[i],
FpUtils.isFinite(testCases[i]), (i >= 3));
// isInfinite
failures+=Tests.test("FpUtils.isInfinite(double)", testCases[i],
FpUtils.isInfinite(testCases[i]), (i==1 || i==2));
// isUnorderd
for(int j = 0; j < testCases.length; j++) {
failures+=Tests.test("FpUtils.isUnordered(double, double)", testCases[i],testCases[j],
FpUtils.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
}
}
return failures;
}
/* ******************** copySign tests******************************** */
public static int testFloatCopySign() {
int failures = 0;
// testCases[0] are logically positive numbers;
// testCases[1] are negative numbers.
float testCases [][] = {
{+0.0f,
Float.MIN_VALUE,
Float_MAX_SUBNORMALmm,
Float_MAX_SUBNORMAL,
FloatConsts.MIN_NORMAL,
1.0f,
3.0f,
Float_MAX_VALUEmm,
Float.MAX_VALUE,
infinityF,
},
{-infinityF,
-Float.MAX_VALUE,
-3.0f,
-1.0f,
-FloatConsts.MIN_NORMAL,
-Float_MAX_SUBNORMALmm,
-Float_MAX_SUBNORMAL,
-Float.MIN_VALUE,
-0.0f}
};
float NaNs[] = {Float.intBitsToFloat(0x7fc00000), // "positive" NaN
Float.intBitsToFloat(0xFfc00000)}; // "negative" NaN
// Tests shared between raw and non-raw versions
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
for(int m = 0; m < testCases[i].length; m++) {
for(int n = 0; n < testCases[j].length; n++) {
// copySign(magnitude, sign)
failures+=Tests.test("Math.copySign(float,float)",
testCases[i][m],testCases[j][n],
Math.copySign(testCases[i][m], testCases[j][n]),
(j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
failures+=Tests.test("StrictMath.copySign(float,float)",
testCases[i][m],testCases[j][n],
StrictMath.copySign(testCases[i][m], testCases[j][n]),
(j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
}
}
}
}
// For rawCopySign, NaN may effectively have either sign bit
// while for copySign NaNs are treated as if they always have
// a zero sign bit (i.e. as positive numbers)
for(int i = 0; i < 2; i++) {
for(int j = 0; j < NaNs.length; j++) {
for(int m = 0; m < testCases[i].length; m++) {
// copySign(magnitude, sign)
failures += (Math.abs(Math.copySign(testCases[i][m], NaNs[j])) ==
Math.abs(testCases[i][m])) ? 0:1;
failures+=Tests.test("StrictMath.copySign(float,float)",
testCases[i][m], NaNs[j],
StrictMath.copySign(testCases[i][m], NaNs[j]),
Math.abs(testCases[i][m]) );
}
}
}
return failures;
}
public static int testDoubleCopySign() {
int failures = 0;
// testCases[0] are logically positive numbers;
// testCases[1] are negative numbers.
double testCases [][] = {
{+0.0d,
Double.MIN_VALUE,
Double_MAX_SUBNORMALmm,
Double_MAX_SUBNORMAL,
DoubleConsts.MIN_NORMAL,
1.0d,
3.0d,
Double_MAX_VALUEmm,
Double.MAX_VALUE,
infinityD,
},
{-infinityD,
-Double.MAX_VALUE,
-3.0d,
-1.0d,
-DoubleConsts.MIN_NORMAL,
-Double_MAX_SUBNORMALmm,
-Double_MAX_SUBNORMAL,
-Double.MIN_VALUE,
-0.0d}
};
double NaNs[] = {Double.longBitsToDouble(0x7ff8000000000000L), // "positive" NaN
Double.longBitsToDouble(0xfff8000000000000L), // "negative" NaN
Double.longBitsToDouble(0x7FF0000000000001L),
Double.longBitsToDouble(0xFFF0000000000001L),
Double.longBitsToDouble(0x7FF8555555555555L),
Double.longBitsToDouble(0xFFF8555555555555L),
Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL),
Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL),
Double.longBitsToDouble(0x7FFDeadBeef00000L),
Double.longBitsToDouble(0xFFFDeadBeef00000L),
Double.longBitsToDouble(0x7FFCafeBabe00000L),
Double.longBitsToDouble(0xFFFCafeBabe00000L)};
// Tests shared between Math and StrictMath versions
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
for(int m = 0; m < testCases[i].length; m++) {
for(int n = 0; n < testCases[j].length; n++) {
// copySign(magnitude, sign)
failures+=Tests.test("MathcopySign(double,double)",
testCases[i][m],testCases[j][n],
Math.copySign(testCases[i][m], testCases[j][n]),
(j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
failures+=Tests.test("StrictMath.copySign(double,double)",
testCases[i][m],testCases[j][n],
StrictMath.copySign(testCases[i][m], testCases[j][n]),
(j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
}
}
}
}
// For Math.copySign, NaN may effectively have either sign bit
// while for StrictMath.copySign NaNs are treated as if they
// always have a zero sign bit (i.e. as positive numbers)
for(int i = 0; i < 2; i++) {
for(int j = 0; j < NaNs.length; j++) {
for(int m = 0; m < testCases[i].length; m++) {
// copySign(magnitude, sign)
failures += (Math.abs(Math.copySign(testCases[i][m], NaNs[j])) ==
Math.abs(testCases[i][m])) ? 0:1;
failures+=Tests.test("StrictMath.copySign(double,double)",
testCases[i][m], NaNs[j],
StrictMath.copySign(testCases[i][m], NaNs[j]),
Math.abs(testCases[i][m]) );
}
}
}
return failures;
}
/* ************************ scalb tests ******************************* */
static int testScalbCase(float value, int scale_factor, float expected) {
int failures=0;
failures+=Tests.test("Math.scalb(float,int)",
value, scale_factor,
Math.scalb(value, scale_factor), expected);
failures+=Tests.test("Math.scalb(float,int)",
-value, scale_factor,
Math.scalb(-value, scale_factor), -expected);
failures+=Tests.test("StrictMath.scalb(float,int)",
value, scale_factor,
StrictMath.scalb(value, scale_factor), expected);
failures+=Tests.test("StrictMath.scalb(float,int)",
-value, scale_factor,
StrictMath.scalb(-value, scale_factor), -expected);
return failures;
}
public static int testFloatScalb() {
int failures=0;
int MAX_SCALE = FloatConsts.MAX_EXPONENT + -FloatConsts.MIN_EXPONENT +
FloatConsts.SIGNIFICAND_WIDTH + 1;
// Arguments x, where scalb(x,n) is x for any n.
float [] identityTestCases = {NaNf,
-0.0f,
+0.0f,
infinityF,
-infinityF
};
float [] subnormalTestCases = {
Float.MIN_VALUE,
3.0f*Float.MIN_VALUE,
Float_MAX_SUBNORMALmm,
Float_MAX_SUBNORMAL
};
float [] someTestCases = {
Float.MIN_VALUE,
3.0f*Float.MIN_VALUE,
Float_MAX_SUBNORMALmm,
Float_MAX_SUBNORMAL,
FloatConsts.MIN_NORMAL,
1.0f,
2.0f,
3.0f,
(float)Math.PI,
Float_MAX_VALUEmm,
Float.MAX_VALUE
};
int [] oneMultiplyScalingFactors = {
FloatConsts.MIN_EXPONENT,
FloatConsts.MIN_EXPONENT+1,
-3,
-2,
-1,
0,
1,
2,
3,
FloatConsts.MAX_EXPONENT-1,
FloatConsts.MAX_EXPONENT
};
int [] manyScalingFactors = {
Integer.MIN_VALUE,
Integer.MIN_VALUE+1,
-MAX_SCALE -1,
-MAX_SCALE,
-MAX_SCALE+1,
2*FloatConsts.MIN_EXPONENT-1, // -253
2*FloatConsts.MIN_EXPONENT, // -252
2*FloatConsts.MIN_EXPONENT+1, // -251
FpUtils.ilogb(Float.MIN_VALUE)-1, // -150
FpUtils.ilogb(Float.MIN_VALUE), // -149
-FloatConsts.MAX_EXPONENT, // -127
FloatConsts.MIN_EXPONENT, // -126
-2,
-1,
0,
1,
2,
FloatConsts.MAX_EXPONENT-1, // 126
FloatConsts.MAX_EXPONENT, // 127
FloatConsts.MAX_EXPONENT+1, // 128
2*FloatConsts.MAX_EXPONENT-1, // 253
2*FloatConsts.MAX_EXPONENT, // 254
2*FloatConsts.MAX_EXPONENT+1, // 255
MAX_SCALE-1,
MAX_SCALE,
MAX_SCALE+1,
Integer.MAX_VALUE-1,
Integer.MAX_VALUE
};
// Test cases where scaling is always a no-op
for(int i=0; i < identityTestCases.length; i++) {
for(int j=0; j < manyScalingFactors.length; j++) {
failures += testScalbCase(identityTestCases[i],
manyScalingFactors[j],
identityTestCases[i]);
}
}
// Test cases where result is 0.0 or infinity due to magnitude
// of the scaling factor
for(int i=0; i < someTestCases.length; i++) {
for(int j=0; j < manyScalingFactors.length; j++) {
int scaleFactor = manyScalingFactors[j];
if (Math.abs(scaleFactor) >= MAX_SCALE) {
float value = someTestCases[i];
failures+=testScalbCase(value,
scaleFactor,
FpUtils.copySign( (scaleFactor>0?infinityF:0.0f), value) );
}
}
}
// Test cases that could be done with one floating-point
// multiply.
for(int i=0; i < someTestCases.length; i++) {
for(int j=0; j < oneMultiplyScalingFactors.length; j++) {
int scaleFactor = oneMultiplyScalingFactors[j];
float value = someTestCases[i];
failures+=testScalbCase(value,
scaleFactor,
value*powerOfTwoF(scaleFactor));
}
}
// Create 2^MAX_EXPONENT
float twoToTheMaxExp = 1.0f; // 2^0
for(int i = 0; i < FloatConsts.MAX_EXPONENT; i++)
twoToTheMaxExp *=2.0f;
// Scale-up subnormal values until they all overflow
for(int i=0; i < subnormalTestCases.length; i++) {
float scale = 1.0f; // 2^j
float value = subnormalTestCases[i];
for(int j=FloatConsts.MAX_EXPONENT*2; j < MAX_SCALE; j++) { // MAX_SCALE -1 should cause overflow
int scaleFactor = j;
failures+=testScalbCase(value,
scaleFactor,
(FpUtils.ilogb(value) +j > FloatConsts.MAX_EXPONENT ) ?
FpUtils.copySign(infinityF, value) : // overflow
// calculate right answer
twoToTheMaxExp*(twoToTheMaxExp*(scale*value)) );
scale*=2.0f;
}
}
// Scale down a large number until it underflows. By scaling
// down MAX_NORMALmm, the first subnormal result will be exact
// but the next one will round -- all those results can be
// checked by halving a separate value in the loop. Actually,
// we can keep halving and checking until the product is zero
// since:
//
// 1. If the scalb of MAX_VALUEmm is subnormal and *not* exact
// it will round *up*
//
// 2. When rounding first occurs in the expected product, it
// too rounds up, to 2^-MAX_EXPONENT.
//
// Halving expected after rounding happends to give the same
// result as the scalb operation.
float expected = Float_MAX_VALUEmm *0.5f;
for(int i = -1; i > -MAX_SCALE; i--) {
failures+=testScalbCase(Float_MAX_VALUEmm, i, expected);
expected *= 0.5f;
}
// Tricky rounding tests:
// Scale down a large number into subnormal range such that if
// scalb is being implemented with multiple floating-point
// multiplies, the value would round twice if the multiplies
// were done in the wrong order.
float value = 0x8.0000bP-5f;
expected = 0x1.00001p-129f;
for(int i = 0; i < 129; i++) {
failures+=testScalbCase(value,
-127-i,
expected);
value *=2.0f;
}
return failures;
}
static int testScalbCase(double value, int scale_factor, double expected) {
int failures=0;
failures+=Tests.test("Math.scalb(double,int)",
value, scale_factor,
Math.scalb(value, scale_factor), expected);
failures+=Tests.test("Math.scalb(double,int)",
-value, scale_factor,
Math.scalb(-value, scale_factor), -expected);
failures+=Tests.test("StrictMath.scalb(double,int)",
value, scale_factor,
StrictMath.scalb(value, scale_factor), expected);
failures+=Tests.test("StrictMath.scalb(double,int)",
-value, scale_factor,
StrictMath.scalb(-value, scale_factor), -expected);
return failures;
}
public static int testDoubleScalb() {
int failures=0;
int MAX_SCALE = DoubleConsts.MAX_EXPONENT + -DoubleConsts.MIN_EXPONENT +
DoubleConsts.SIGNIFICAND_WIDTH + 1;
// Arguments x, where scalb(x,n) is x for any n.
double [] identityTestCases = {NaNd,
-0.0,
+0.0,
infinityD,
};
double [] subnormalTestCases = {
Double.MIN_VALUE,
3.0d*Double.MIN_VALUE,
Double_MAX_SUBNORMALmm,
Double_MAX_SUBNORMAL
};
double [] someTestCases = {
Double.MIN_VALUE,
3.0d*Double.MIN_VALUE,
Double_MAX_SUBNORMALmm,
Double_MAX_SUBNORMAL,
DoubleConsts.MIN_NORMAL,
1.0d,
2.0d,
3.0d,
Math.PI,
Double_MAX_VALUEmm,
Double.MAX_VALUE
};
int [] oneMultiplyScalingFactors = {
DoubleConsts.MIN_EXPONENT,
DoubleConsts.MIN_EXPONENT+1,
-3,
-2,
-1,
0,
1,
2,
3,
DoubleConsts.MAX_EXPONENT-1,
DoubleConsts.MAX_EXPONENT
};
int [] manyScalingFactors = {
Integer.MIN_VALUE,
Integer.MIN_VALUE+1,
-MAX_SCALE -1,
-MAX_SCALE,
-MAX_SCALE+1,
2*DoubleConsts.MIN_EXPONENT-1, // -2045
2*DoubleConsts.MIN_EXPONENT, // -2044
2*DoubleConsts.MIN_EXPONENT+1, // -2043
FpUtils.ilogb(Double.MIN_VALUE)-1, // -1076
FpUtils.ilogb(Double.MIN_VALUE), // -1075
-DoubleConsts.MAX_EXPONENT, // -1023
DoubleConsts.MIN_EXPONENT, // -1022
-2,
-1,
0,
1,
2,
DoubleConsts.MAX_EXPONENT-1, // 1022
DoubleConsts.MAX_EXPONENT, // 1023
DoubleConsts.MAX_EXPONENT+1, // 1024
2*DoubleConsts.MAX_EXPONENT-1, // 2045
2*DoubleConsts.MAX_EXPONENT, // 2046
2*DoubleConsts.MAX_EXPONENT+1, // 2047
MAX_SCALE-1,
MAX_SCALE,
MAX_SCALE+1,
Integer.MAX_VALUE-1,
Integer.MAX_VALUE
};
// Test cases where scaling is always a no-op
for(int i=0; i < identityTestCases.length; i++) {
for(int j=0; j < manyScalingFactors.length; j++) {
failures += testScalbCase(identityTestCases[i],
manyScalingFactors[j],
identityTestCases[i]);
}
}
// Test cases where result is 0.0 or infinity due to magnitude
// of the scaling factor
for(int i=0; i < someTestCases.length; i++) {
for(int j=0; j < manyScalingFactors.length; j++) {
int scaleFactor = manyScalingFactors[j];
if (Math.abs(scaleFactor) >= MAX_SCALE) {
double value = someTestCases[i];
failures+=testScalbCase(value,
scaleFactor,
FpUtils.copySign( (scaleFactor>0?infinityD:0.0), value) );
}
}
}
// Test cases that could be done with one floating-point
// multiply.
for(int i=0; i < someTestCases.length; i++) {
for(int j=0; j < oneMultiplyScalingFactors.length; j++) {
int scaleFactor = oneMultiplyScalingFactors[j];
double value = someTestCases[i];
failures+=testScalbCase(value,
scaleFactor,
value*powerOfTwoD(scaleFactor));
}
}
// Create 2^MAX_EXPONENT
double twoToTheMaxExp = 1.0; // 2^0
for(int i = 0; i < DoubleConsts.MAX_EXPONENT; i++)
twoToTheMaxExp *=2.0;
// Scale-up subnormal values until they all overflow
for(int i=0; i < subnormalTestCases.length; i++) {
double scale = 1.0; // 2^j
double value = subnormalTestCases[i];
for(int j=DoubleConsts.MAX_EXPONENT*2; j < MAX_SCALE; j++) { // MAX_SCALE -1 should cause overflow
int scaleFactor = j;
failures+=testScalbCase(value,
scaleFactor,
(FpUtils.ilogb(value) +j > DoubleConsts.MAX_EXPONENT ) ?
FpUtils.copySign(infinityD, value) : // overflow
// calculate right answer
twoToTheMaxExp*(twoToTheMaxExp*(scale*value)) );
scale*=2.0;
}
}
// Scale down a large number until it underflows. By scaling
// down MAX_NORMALmm, the first subnormal result will be exact
// but the next one will round -- all those results can be
// checked by halving a separate value in the loop. Actually,
// we can keep halving and checking until the product is zero
// since:
//
// 1. If the scalb of MAX_VALUEmm is subnormal and *not* exact
// it will round *up*
//
// 2. When rounding first occurs in the expected product, it
// too rounds up, to 2^-MAX_EXPONENT.
//
// Halving expected after rounding happends to give the same
// result as the scalb operation.
double expected = Double_MAX_VALUEmm *0.5f;
for(int i = -1; i > -MAX_SCALE; i--) {
failures+=testScalbCase(Double_MAX_VALUEmm, i, expected);
expected *= 0.5;
}
// Tricky rounding tests:
// Scale down a large number into subnormal range such that if
// scalb is being implemented with multiple floating-point
// multiplies, the value would round twice if the multiplies
// were done in the wrong order.
double value = 0x1.000000000000bP-1;
expected = 0x0.2000000000001P-1022;
for(int i = 0; i < DoubleConsts.MAX_EXPONENT+2; i++) {
failures+=testScalbCase(value,
-1024-i,
expected);
value *=2.0;
}
return failures;
}
/* ************************* ulp tests ******************************* */
/*
* Test Math.ulp and StrictMath.ulp with +d and -d.
*/
static int testUlpCase(float f, float expected) {
float minus_f = -f;
int failures=0;
failures+=Tests.test("Math.ulp(float)", f,
Math.ulp(f), expected);
failures+=Tests.test("Math.ulp(float)", minus_f,
Math.ulp(minus_f), expected);
failures+=Tests.test("StrictMath.ulp(float)", f,
StrictMath.ulp(f), expected);
failures+=Tests.test("StrictMath.ulp(float)", minus_f,
StrictMath.ulp(minus_f), expected);
return failures;
}
static int testUlpCase(double d, double expected) {
double minus_d = -d;
int failures=0;
failures+=Tests.test("Math.ulp(double)", d,
Math.ulp(d), expected);
failures+=Tests.test("Math.ulp(double)", minus_d,
Math.ulp(minus_d), expected);
failures+=Tests.test("StrictMath.ulp(double)", d,
StrictMath.ulp(d), expected);
failures+=Tests.test("StrictMath.ulp(double)", minus_d,
StrictMath.ulp(minus_d), expected);
return failures;
}
public static int testFloatUlp() {
int failures = 0;
float [] specialValues = {NaNf,
Float.POSITIVE_INFINITY,
+0.0f,
+1.0f,
+2.0f,
+16.0f,
+Float.MIN_VALUE,
+Float_MAX_SUBNORMAL,
+FloatConsts.MIN_NORMAL,
+Float.MAX_VALUE
};
float [] specialResults = {NaNf,
Float.POSITIVE_INFINITY,
Float.MIN_VALUE,
powerOfTwoF(-23),
powerOfTwoF(-22),
powerOfTwoF(-19),
Float.MIN_VALUE,
Float.MIN_VALUE,
Float.MIN_VALUE,
powerOfTwoF(104)
};
// Special value tests
for(int i = 0; i < specialValues.length; i++) {
failures += testUlpCase(specialValues[i], specialResults[i]);
}
// Normal exponent tests
for(int i = FloatConsts.MIN_EXPONENT; i <= FloatConsts.MAX_EXPONENT; i++) {
float expected;
// Create power of two
float po2 = powerOfTwoF(i);
expected = FpUtils.scalb(1.0f, i - (FloatConsts.SIGNIFICAND_WIDTH-1));
failures += testUlpCase(po2, expected);
// Generate some random bit patterns for the significand
for(int j = 0; j < 10; j++) {
int randSignif = rand.nextInt();
float randFloat;
randFloat = Float.intBitsToFloat( // Exponent
(Float.floatToIntBits(po2)&
(~FloatConsts.SIGNIF_BIT_MASK)) |
// Significand
(randSignif &
FloatConsts.SIGNIF_BIT_MASK) );
failures += testUlpCase(randFloat, expected);
}
if (i > FloatConsts.MIN_EXPONENT) {
float po2minus = FpUtils.nextAfter(po2,
Float.NEGATIVE_INFINITY);
failures += testUlpCase(po2minus, expected/2.0f);
}
}
// Subnormal tests
/*
* Start with MIN_VALUE, left shift, test high value, low
* values, and random in between.
*
* Use nextAfter to calculate, high value of previous binade,
* loop count i will indicate how many random bits, if any are
* needed.
*/
float top=Float.MIN_VALUE;
for( int i = 1;
i < FloatConsts.SIGNIFICAND_WIDTH;
i++, top *= 2.0f) {
failures += testUlpCase(top, Float.MIN_VALUE);
// Test largest value in next smaller binade
if (i >= 3) {// (i == 1) would test 0.0;
// (i == 2) would just retest MIN_VALUE
testUlpCase(FpUtils.nextAfter(top, 0.0f),
Float.MIN_VALUE);
if( i >= 10) {
// create a bit mask with (i-1) 1's in the low order
// bits
int mask = ~((~0)<<(i-1));
float randFloat = Float.intBitsToFloat( // Exponent
Float.floatToIntBits(top) |
// Significand
(rand.nextInt() & mask ) ) ;
failures += testUlpCase(randFloat, Float.MIN_VALUE);
}
}
}
return failures;
}
public static int testDoubleUlp() {
int failures = 0;
double [] specialValues = {NaNd,
Double.POSITIVE_INFINITY,
+0.0d,
+1.0d,
+2.0d,
+16.0d,
+Double.MIN_VALUE,
+Double_MAX_SUBNORMAL,
+DoubleConsts.MIN_NORMAL,
+Double.MAX_VALUE
};
double [] specialResults = {NaNf,
Double.POSITIVE_INFINITY,
Double.MIN_VALUE,
powerOfTwoD(-52),
powerOfTwoD(-51),
powerOfTwoD(-48),
Double.MIN_VALUE,
Double.MIN_VALUE,
Double.MIN_VALUE,
powerOfTwoD(971)
};
// Special value tests
for(int i = 0; i < specialValues.length; i++) {
failures += testUlpCase(specialValues[i], specialResults[i]);
}
// Normal exponent tests
for(int i = DoubleConsts.MIN_EXPONENT; i <= DoubleConsts.MAX_EXPONENT; i++) {
double expected;
// Create power of two
double po2 = powerOfTwoD(i);
expected = FpUtils.scalb(1.0, i - (DoubleConsts.SIGNIFICAND_WIDTH-1));
failures += testUlpCase(po2, expected);
// Generate some random bit patterns for the significand
for(int j = 0; j < 10; j++) {
long randSignif = rand.nextLong();
double randDouble;
randDouble = Double.longBitsToDouble( // Exponent
(Double.doubleToLongBits(po2)&
(~DoubleConsts.SIGNIF_BIT_MASK)) |
// Significand
(randSignif &
DoubleConsts.SIGNIF_BIT_MASK) );
failures += testUlpCase(randDouble, expected);
}
if (i > DoubleConsts.MIN_EXPONENT) {
double po2minus = FpUtils.nextAfter(po2,
Double.NEGATIVE_INFINITY);
failures += testUlpCase(po2minus, expected/2.0f);
}
}
// Subnormal tests
/*
* Start with MIN_VALUE, left shift, test high value, low
* values, and random in between.
*
* Use nextAfter to calculate, high value of previous binade,
* loop count i will indicate how many random bits, if any are
* needed.
*/
double top=Double.MIN_VALUE;
for( int i = 1;
i < DoubleConsts.SIGNIFICAND_WIDTH;
i++, top *= 2.0f) {
failures += testUlpCase(top, Double.MIN_VALUE);
// Test largest value in next smaller binade
if (i >= 3) {// (i == 1) would test 0.0;
// (i == 2) would just retest MIN_VALUE
testUlpCase(FpUtils.nextAfter(top, 0.0f),
Double.MIN_VALUE);
if( i >= 10) {
// create a bit mask with (i-1) 1's in the low order
// bits
int mask = ~((~0)<<(i-1));
double randDouble = Double.longBitsToDouble( // Exponent
Double.doubleToLongBits(top) |
// Significand
(rand.nextLong() & mask ) ) ;
failures += testUlpCase(randDouble, Double.MIN_VALUE);
}
}
}
return failures;
}
public static int testFloatSignum() {
int failures = 0;
float testCases [][] = {
{NaNf, NaNf},
{-infinityF, -1.0f},
{-Float.MAX_VALUE, -1.0f},
{-FloatConsts.MIN_NORMAL, -1.0f},
{-1.0f, -1.0f},
{-2.0f, -1.0f},
{-Float_MAX_SUBNORMAL, -1.0f},
{-Float.MIN_VALUE, -1.0f},
{-0.0f, -0.0f},
{+0.0f, +0.0f},
{Float.MIN_VALUE, 1.0f},
{Float_MAX_SUBNORMALmm, 1.0f},
{Float_MAX_SUBNORMAL, 1.0f},
{FloatConsts.MIN_NORMAL, 1.0f},
{1.0f, 1.0f},
{2.0f, 1.0f},
{Float_MAX_VALUEmm, 1.0f},
{Float.MAX_VALUE, 1.0f},
{infinityF, 1.0f}
};
for(int i = 0; i < testCases.length; i++) {
failures+=Tests.test("Math.signum(float)",
testCases[i][0], Math.signum(testCases[i][0]), testCases[i][1]);
failures+=Tests.test("StrictMath.signum(float)",
testCases[i][0], StrictMath.signum(testCases[i][0]), testCases[i][1]);
}
return failures;
}
public static int testDoubleSignum() {
int failures = 0;
double testCases [][] = {
{NaNd, NaNd},
{-infinityD, -1.0},
{-Double.MAX_VALUE, -1.0},
{-DoubleConsts.MIN_NORMAL, -1.0},
{-1.0, -1.0},
{-2.0, -1.0},
{-Double_MAX_SUBNORMAL, -1.0},
{-Double.MIN_VALUE, -1.0d},
{-0.0d, -0.0d},
{+0.0d, +0.0d},
{Double.MIN_VALUE, 1.0},
{Double_MAX_SUBNORMALmm, 1.0},
{Double_MAX_SUBNORMAL, 1.0},
{DoubleConsts.MIN_NORMAL, 1.0},
{1.0, 1.0},
{2.0, 1.0},
{Double_MAX_VALUEmm, 1.0},
{Double.MAX_VALUE, 1.0},
{infinityD, 1.0}
};
for(int i = 0; i < testCases.length; i++) {
failures+=Tests.test("Math.signum(double)",
testCases[i][0], Math.signum(testCases[i][0]), testCases[i][1]);
failures+=Tests.test("StrictMath.signum(double)",
testCases[i][0], StrictMath.signum(testCases[i][0]), testCases[i][1]);
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += testFloatGetExponent();
failures += testDoubleGetExponent();
failures += testFloatNextAfter();
failures += testDoubleNextAfter();
failures += testFloatNextUp();
failures += testDoubleNextUp();
failures += testFloatNextDown();
failures += testDoubleNextDown();
failures += testFloatBooleanMethods();
failures += testDoubleBooleanMethods();
failures += testFloatCopySign();
failures += testDoubleCopySign();
failures += testFloatScalb();
failures += testDoubleScalb();
failures += testFloatUlp();
failures += testDoubleUlp();
failures += testFloatSignum();
failures += testDoubleSignum();
if (failures > 0) {
System.err.println("Testing the recommended functions incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4074599 4939441
* @summary Tests for {Math, StrictMath}.log10
* @author Joseph D. Darcy
*/
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class Log10Tests {
private Log10Tests(){}
static final double infinityD = Double.POSITIVE_INFINITY;
static final double NaNd = Double.NaN;
static final double LN_10 = StrictMath.log(10.0);
// Initialize shared random number generator
static java.util.Random rand = new java.util.Random(0L);
static int testLog10Case(double input, double expected) {
int failures=0;
failures+=Tests.test("Math.log10(double)", input,
Math.log10(input), expected);
failures+=Tests.test("StrictMath.log10(double)", input,
StrictMath.log10(input), expected);
return failures;
}
static int testLog10() {
int failures = 0;
double [][] testCases = {
{Double.NaN, NaNd},
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
{Double.NEGATIVE_INFINITY, NaNd},
{-8.0, NaNd},
{-1.0, NaNd},
{-DoubleConsts.MIN_NORMAL, NaNd},
{-Double.MIN_VALUE, NaNd},
{-0.0, -infinityD},
{+0.0, -infinityD},
{+1.0, 0.0},
{Double.POSITIVE_INFINITY, infinityD},
};
// Test special cases
for(int i = 0; i < testCases.length; i++) {
failures += testLog10Case(testCases[i][0],
testCases[i][1]);
}
// Test log10(10^n) == n for integer n; 10^n, n < 0 is not
// exactly representable as a floating-point value -- up to
// 10^22 can be represented exactly
double testCase = 1.0;
for(int i = 0; i < 23; i++) {
failures += testLog10Case(testCase, i);
testCase *= 10.0;
}
// Test for gross inaccuracy by comparing to log; should be
// within a few ulps of log(x)/log(10)
for(int i = 0; i < 10000; i++) {
double input = Double.longBitsToDouble(rand.nextLong());
if(! FpUtils.isFinite(input))
continue; // avoid testing NaN and infinite values
else {
input = Math.abs(input);
double expected = StrictMath.log(input)/LN_10;
if( ! FpUtils.isFinite(expected))
continue; // if log(input) overflowed, try again
else {
double result;
if( Math.abs(((result=Math.log10(input)) - expected)/Math.ulp(expected)) > 3) {
failures++;
System.err.println("For input " + input +
", Math.log10 was more than 3 ulps different from " +
"log(input)/log(10): log10(input) = " + result +
"\tlog(input)/log(10) = " + expected);
}
if( Math.abs(((result=StrictMath.log10(input)) - expected)/Math.ulp(expected)) > 3) {
failures++;
System.err.println("For input " + input +
", StrictMath.log10 was more than 3 ulps different from " +
"log(input)/log(10): log10(input) = " + result +
"\tlog(input)/log(10) = " + expected);
}
}
}
}
// Test for accuracy and monotonicity near log10(1.0). From
// the Taylor expansion of log,
// log10(1+z) ~= (z -(z^2)/2)/LN_10;
{
double neighbors[] = new double[40];
double neighborsStrict[] = new double[40];
double z = Double.NaN;
// Test inputs greater than 1.0.
neighbors[0] = Math.log10(1.0);
neighborsStrict[0] = StrictMath.log10(1.0);
double input[] = new double[40];
int half = input.length/2;
// Initialize input to the 40 consecutive double values
// "centered" at 1.0.
double up = Double.NaN;
double down = Double.NaN;
for(int i = 0; i < half; i++) {
if (i == 0) {
input[half] = 1.0;
up = FpUtils.nextUp(1.0);
down = FpUtils.nextDown(1.0);
} else {
input[half + i] = up;
input[half - i] = down;
up = FpUtils.nextUp(up);
down = FpUtils.nextDown(down);
}
}
input[0] = FpUtils.nextDown(input[1]);
for(int i = 0; i < neighbors.length; i++) {
neighbors[i] = Math.log10(input[i]);
neighborsStrict[i] = StrictMath.log10(input[i]);
// Test accuracy.
z = input[i] - 1.0;
double expected = (z - (z*z)*0.5)/LN_10;
if ( Math.abs(neighbors[i] - expected ) > 3*Math.ulp(expected) ) {
failures++;
System.err.println("For input near 1.0 " + input[i] +
", Math.log10(1+z) was more than 3 ulps different from " +
"(z-(z^2)/2)/ln(10): log10(input) = " + neighbors[i] +
"\texpected about = " + expected);
}
if ( Math.abs(neighborsStrict[i] - expected ) > 3*Math.ulp(expected) ) {
failures++;
System.err.println("For input near 1.0 " + input[i] +
", StrictMath.log10(1+z) was more than 3 ulps different from " +
"(z-(z^2)/2)/ln(10): log10(input) = " + neighborsStrict[i] +
"\texpected about = " + expected);
}
// Test monotonicity
if( i > 0) {
if( neighbors[i-1] > neighbors[i] ) {
failures++;
System.err.println("Monotonicity failure for Math.log10 at " + input[i] +
" and prior value.");
}
if( neighborsStrict[i-1] > neighborsStrict[i] ) {
failures++;
System.err.println("Monotonicity failure for StrictMath.log10 at " + input[i] +
" and prior value.");
}
}
}
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += testLog10();
if (failures > 0) {
System.err.println("Testing log10 incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851638 4939441
* @summary Tests for {Math, StrictMath}.log1p
* @author Joseph D. Darcy
*/
import sun.misc.DoubleConsts;
import sun.misc.FpUtils;
public class Log1pTests {
private Log1pTests(){}
static final double infinityD = Double.POSITIVE_INFINITY;
static final double NaNd = Double.NaN;
/**
* Formulation taken from HP-15C Advanced Functions Handbook, part
* number HP 0015-90011, p 181. This is accurate to a few ulps.
*/
static double hp15cLogp(double x) {
double u = 1.0 + x;
return (u==1.0? x : StrictMath.log(u)*x/(u-1) );
}
/*
* The Taylor expansion of ln(1 + x) for -1 < x <= 1 is:
*
* x - x^2/2 + x^3/3 - ... -(-x^j)/j
*
* Therefore, for small values of x, log1p(x) ~= x. For large
* values of x, log1p(x) ~= log(x).
*
* Also x/(x+1) < ln(1+x) < x
*/
static int testLog1p() {
int failures = 0;
double [][] testCases = {
{Double.NaN, NaNd},
{Double.longBitsToDouble(0x7FF0000000000001L), NaNd},
{Double.longBitsToDouble(0xFFF0000000000001L), NaNd},
{Double.longBitsToDouble(0x7FF8555555555555L), NaNd},
{Double.longBitsToDouble(0xFFF8555555555555L), NaNd},
{Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL), NaNd},
{Double.longBitsToDouble(0x7FFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0xFFFDeadBeef00000L), NaNd},
{Double.longBitsToDouble(0x7FFCafeBabe00000L), NaNd},
{Double.longBitsToDouble(0xFFFCafeBabe00000L), NaNd},
{Double.NEGATIVE_INFINITY, NaNd},
{-8.0, NaNd},
{-1.0, -infinityD},
{-0.0, -0.0},
{+0.0, +0.0},
{infinityD, infinityD},
};
// Test special cases
for(int i = 0; i < testCases.length; i++) {
failures += testLog1pCaseWithUlpDiff(testCases[i][0],
testCases[i][1], 0);
}
// For |x| < 2^-54 log1p(x) ~= x
for(int i = DoubleConsts.MIN_SUB_EXPONENT; i <= -54; i++) {
double d = FpUtils.scalb(2, i);
failures += testLog1pCase(d, d);
failures += testLog1pCase(-d, -d);
}
// For x > 2^53 log1p(x) ~= log(x)
for(int i = 53; i <= DoubleConsts.MAX_EXPONENT; i++) {
double d = FpUtils.scalb(2, i);
failures += testLog1pCaseWithUlpDiff(d, StrictMath.log(d), 2.001);
}
// Construct random values with exponents ranging from -53 to
// 52 and compare against HP-15C formula.
java.util.Random rand = new java.util.Random();
for(int i = 0; i < 1000; i++) {
double d = rand.nextDouble();
d = FpUtils.scalb(d, -53 - FpUtils.ilogb(d));
for(int j = -53; j <= 52; j++) {
failures += testLog1pCaseWithUlpDiff(d, hp15cLogp(d), 5);
d *= 2.0; // increase exponent by 1
}
}
// Test for monotonicity failures near values y-1 where y ~=
// e^x. Test two numbers before and two numbers after each
// chosen value; i.e.
//
// pcNeighbors[] =
// {nextDown(nextDown(pc)),
// nextDown(pc),
// pc,
// nextUp(pc),
// nextUp(nextUp(pc))}
//
// and we test that log1p(pcNeighbors[i]) <= log1p(pcNeighbors[i+1])
{
double pcNeighbors[] = new double[5];
double pcNeighborsLog1p[] = new double[5];
double pcNeighborsStrictLog1p[] = new double[5];
for(int i = -36; i <= 36; i++) {
double pc = StrictMath.pow(Math.E, i) - 1;
pcNeighbors[2] = pc;
pcNeighbors[1] = FpUtils.nextDown(pc);
pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
pcNeighbors[3] = FpUtils.nextUp(pc);
pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
for(int j = 0; j < pcNeighbors.length; j++) {
pcNeighborsLog1p[j] = Math.log1p(pcNeighbors[j]);
pcNeighborsStrictLog1p[j] = StrictMath.log1p(pcNeighbors[j]);
}
for(int j = 0; j < pcNeighborsLog1p.length-1; j++) {
if(pcNeighborsLog1p[j] > pcNeighborsLog1p[j+1] ) {
failures++;
System.err.println("Monotonicity failure for Math.log1p on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsLog1p[j] + " and " +
pcNeighborsLog1p[j+1] );
}
if(pcNeighborsStrictLog1p[j] > pcNeighborsStrictLog1p[j+1] ) {
failures++;
System.err.println("Monotonicity failure for StrictMath.log1p on " +
pcNeighbors[j] + " and " +
pcNeighbors[j+1] + "\n\treturned " +
pcNeighborsStrictLog1p[j] + " and " +
pcNeighborsStrictLog1p[j+1] );
}
}
}
}
return failures;
}
public static int testLog1pCase(double input,
double expected) {
return testLog1pCaseWithUlpDiff(input, expected, 1);
}
public static int testLog1pCaseWithUlpDiff(double input,
double expected,
double ulps) {
int failures = 0;
failures += Tests.testUlpDiff("Math.lop1p(double",
input, Math.log1p(input),
expected, ulps);
failures += Tests.testUlpDiff("StrictMath.log1p(double",
input, StrictMath.log1p(input),
expected, ulps);
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += testLog1p();
if (failures > 0) {
System.err.println("Testing log1p incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 1997 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
@bug 4010528 4010529
@summary Math.min and Math.max should treat negative zero as strictly
less than positive zero
*/
public class MinMax {
static void go(String what, float result, float correctResult) {
String v = what + ": got " + result + ", expected " + correctResult;
if (!(Float.toString(result).equals(Float.toString(correctResult))))
throw new RuntimeException(v);
System.err.println(v);
}
static void go(String what, double result, double correctResult) {
String v = what + ": got " + result + ", expected " + correctResult;
if (!(Double.toString(result).equals(Double.toString(correctResult))))
throw new RuntimeException(v);
System.err.println(v);
}
public static void main(String[] args) {
float fnz = -0.0f;
float fpz = +0.0f;
go("Math.min(fnz, fnz)", Math.min(fnz, fnz), fnz);
go("Math.min(fnz, fpz)", Math.min(fnz, fpz), fnz);
go("Math.min(fpz, fnz)", Math.min(fpz, fnz), fnz);
go("Math.min(fpz, fpz)", Math.min(fpz, fpz), fpz);
go("Math.min(-1.0f, fnz)", Math.min(-1.0f, fnz), -1.0f);
go("Math.min(-1.0f, fpz)", Math.min(-1.0f, fpz), -1.0f);
go("Math.min(+1.0f, fnz)", Math.min(+1.0f, fnz), fnz);
go("Math.min(+1.0f, fpz)", Math.min(+1.0f, fpz), fpz);
go("Math.min(-1.0f, +1.0f)", Math.min(-1.0f, +1.0f), -1.0f);
go("Math.min(fnz, -1.0f)", Math.min(fnz, -1.0f), -1.0f);
go("Math.min(fpz, -1.0f)", Math.min(fpz, -1.0f), -1.0f);
go("Math.min(fnz, +1.0f)", Math.min(fnz, +1.0f), fnz);
go("Math.min(fpz, +1.0f)", Math.min(fpz, +1.0f), fpz);
go("Math.min(+1.0f, -1.0f)", Math.min(+1.0f, -1.0f), -1.0f);
go("Math.max(fnz, fnz)", Math.max(fnz, fnz), fnz);
go("Math.max(fnz, fpz)", Math.max(fnz, fpz), fpz);
go("Math.max(fpz, fnz)", Math.max(fpz, fnz), fpz);
go("Math.max(fpz, fpz)", Math.max(fpz, fpz), fpz);
go("Math.max(-1.0f, fnz)", Math.max(-1.0f, fnz), fnz);
go("Math.max(-1.0f, fpz)", Math.max(-1.0f, fpz), fpz);
go("Math.max(+1.0f, fnz)", Math.max(+1.0f, fnz), +1.0f);
go("Math.max(+1.0f, fpz)", Math.max(+1.0f, fpz), +1.0f);
go("Math.max(-1.0f, +1.0f)", Math.max(-1.0f, +1.0f), +1.0f);
go("Math.max(fnz, -1.0f)", Math.max(fnz, -1.0f), fnz);
go("Math.max(fpz, -1.0f)", Math.max(fpz, -1.0f), fpz);
go("Math.max(fnz, +1.0f)", Math.max(fnz, +1.0f), +1.0f);
go("Math.max(fpz, +1.0f)", Math.max(fpz, +1.0f), +1.0f);
go("Math.max(+1.0f, -1.0f)", Math.max(+1.0f, -1.0f), +1.0f);
double dnz = -0.0d;
double dpz = +0.0d;
go("Math.min(dnz, dnz)", Math.min(dnz, dnz), dnz);
go("Math.min(dnz, dpz)", Math.min(dnz, dpz), dnz);
go("Math.min(dpz, dnz)", Math.min(dpz, dnz), dnz);
go("Math.min(dpz, dpz)", Math.min(dpz, dpz), dpz);
go("Math.min(-1.0d, dnz)", Math.min(-1.0d, dnz), -1.0d);
go("Math.min(-1.0d, dpz)", Math.min(-1.0d, dpz), -1.0d);
go("Math.min(+1.0d, dnz)", Math.min(+1.0d, dnz), dnz);
go("Math.min(+1.0d, dpz)", Math.min(+1.0d, dpz), dpz);
go("Math.min(-1.0d, +1.0d)", Math.min(-1.0d, +1.0d), -1.0d);
go("Math.min(dnz, -1.0d)", Math.min(dnz, -1.0d), -1.0d);
go("Math.min(dpz, -1.0d)", Math.min(dpz, -1.0d), -1.0d);
go("Math.min(dnz, +1.0d)", Math.min(dnz, +1.0d), dnz);
go("Math.min(dpz, +1.0d)", Math.min(dpz, +1.0d), dpz);
go("Math.min(+1.0d, -1.0d)", Math.min(+1.0d, -1.0d), -1.0d);
go("Math.max(dnz, dnz)", Math.max(dnz, dnz), dnz);
go("Math.max(dnz, dpz)", Math.max(dnz, dpz), dpz);
go("Math.max(dpz, dnz)", Math.max(dpz, dnz), dpz);
go("Math.max(dpz, dpz)", Math.max(dpz, dpz), dpz);
go("Math.max(-1.0d, dnz)", Math.max(-1.0d, dnz), dnz);
go("Math.max(-1.0d, dpz)", Math.max(-1.0d, dpz), dpz);
go("Math.max(+1.0d, dnz)", Math.max(+1.0d, dnz), +1.0d);
go("Math.max(+1.0d, dpz)", Math.max(+1.0d, dpz), +1.0d);
go("Math.max(-1.0d, +1.0d)", Math.max(-1.0d, +1.0d), +1.0d);
go("Math.max(dnz, -1.0d)", Math.max(dnz, -1.0d), dnz);
go("Math.max(dpz, -1.0d)", Math.max(dpz, -1.0d), dpz);
go("Math.max(dnz, +1.0d)", Math.max(dnz, +1.0d), +1.0d);
go("Math.max(dpz, +1.0d)", Math.max(dpz, +1.0d), +1.0d);
go("Math.max(+1.0d, -1.0d)", Math.max(+1.0d, -1.0d), +1.0d);
}
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4984407 5033578
* @summary Tests for {Math, StrictMath}.pow
* @compile -source 1.5 PowTests.java
* @run main PowTests
* @author Joseph D. Darcy
*/
public class PowTests {
private PowTests(){}
static final double infinityD = Double.POSITIVE_INFINITY;
static int testPowCase(double input1, double input2, double expected) {
int failures = 0;
failures += Tests.test("StrictMath.pow(double, double)", input1, input2,
StrictMath.pow(input1, input2), expected);
failures += Tests.test("Math.pow(double, double)", input1, input2,
Math.pow(input1, input2), expected);
return failures;
}
static int testStrictPowCase(double input1, double input2, double expected) {
int failures = 0;
failures += Tests.test("StrictMath.pow(double, double)", input1, input2,
StrictMath.pow(input1, input2), expected);
return failures;
}
static int testNonstrictPowCase(double input1, double input2, double expected) {
int failures = 0;
failures += Tests.test("Math.pow(double, double)", input1, input2,
Math.pow(input1, input2), expected);
return failures;
}
/*
* Test for bad negation implementation.
*/
static int testPow() {
int failures = 0;
double [][] testCases = {
{-0.0, 3.0, -0.0},
{-0.0, 4.0, 0.0},
{-infinityD, -3.0, -0.0},
{-infinityD, -4.0, 0.0},
};
for (double[] testCase : testCases) {
failures+=testPowCase(testCase[0], testCase[1], testCase[2]);
}
return failures;
}
/*
* Test cross-product of different kinds of arguments.
*/
static int testCrossProduct() {
int failures = 0;
double testData[] = {
Double.NEGATIVE_INFINITY,
/* > -oo */ -Double.MAX_VALUE,
/**/ (double)Long.MIN_VALUE,
/**/ (double) -((1L<<53)+2L),
/**/ (double) -((1L<<53)),
/**/ (double) -((1L<<53)-1L),
/**/ -((double)Integer.MAX_VALUE + 4.0),
/**/ (double)Integer.MIN_VALUE - 1.0,
/**/ (double)Integer.MIN_VALUE,
/**/ (double)Integer.MIN_VALUE + 1.0,
/**/ -Math.PI,
/**/ -3.0,
/**/ -Math.E,
/**/ -2.0,
/**/ -1.0000000000000004,
/* < -1.0 */ -1.0000000000000002, // nextAfter(-1.0, -oo)
-1.0,
/* > -1.0 */ -0.9999999999999999, // nextAfter(-1.0, +oo)
/* > -1.0 */ -0.9999999999999998,
/**/ -0.5,
/**/ -1.0/3.0,
/* < 0.0 */ -Double.MIN_VALUE,
-0.0,
+0.0,
/* > 0.0 */ +Double.MIN_VALUE,
/**/ +1.0/3.0,
/**/ +0.5,
/**/ +0.9999999999999998,
/* < +1.0 */ +0.9999999999999999, // nextAfter(-1.0, +oo)
+1.0,
/* > 1.0 */ +1.0000000000000002, // nextAfter(+1.0, +oo)
/**/ +1.0000000000000004,
/**/ +2.0,
/**/ +Math.E,
/**/ +3.0,
/**/ +Math.PI,
/**/ -(double)Integer.MIN_VALUE - 1.0,
/**/ -(double)Integer.MIN_VALUE,
/**/ -(double)Integer.MIN_VALUE + 1.0,
/**/ (double)Integer.MAX_VALUE + 4.0,
/**/ (double) ((1L<<53)-1L),
/**/ (double) ((1L<<53)),
/**/ (double) ((1L<<53)+2L),
/**/ -(double)Long.MIN_VALUE,
/* < oo */ Double.MAX_VALUE,
Double.POSITIVE_INFINITY,
Double.NaN
};
double NaN = Double.NaN;
for(double x: testData) {
for(double y: testData) {
boolean testPass = false;
double expected=NaN;
double actual;
// First, switch on y
if( Double.isNaN(y)) {
expected = NaN;
} else if (y == 0.0) {
expected = 1.0;
} else if (Double.isInfinite(y) ) {
if(y > 0) { // x ^ (+oo)
if (Math.abs(x) > 1.0) {
expected = Double.POSITIVE_INFINITY;
} else if (Math.abs(x) == 1.0) {
expected = NaN;
} else if (Math.abs(x) < 1.0) {
expected = +0.0;
} else { // x is NaN
assert Double.isNaN(x);
expected = NaN;
}
} else { // x ^ (-oo)
if (Math.abs(x) > 1.0) {
expected = +0.0;
} else if (Math.abs(x) == 1.0) {
expected = NaN;
} else if (Math.abs(x) < 1.0) {
expected = Double.POSITIVE_INFINITY;
} else { // x is NaN
assert Double.isNaN(x);
expected = NaN;
}
} /* end Double.isInfinite(y) */
} else if (y == 1.0) {
expected = x;
} else if (Double.isNaN(x)) { // Now start switching on x
assert y != 0.0;
expected = NaN;
} else if (x == Double.NEGATIVE_INFINITY) {
expected = (y < 0.0) ? f2(y) :f1(y);
} else if (x == Double.POSITIVE_INFINITY) {
expected = (y < 0.0) ? +0.0 : Double.POSITIVE_INFINITY;
} else if (equivalent(x, +0.0)) {
assert y != 0.0;
expected = (y < 0.0) ? Double.POSITIVE_INFINITY: +0.0;
} else if (equivalent(x, -0.0)) {
assert y != 0.0;
expected = (y < 0.0) ? f1(y): f2(y);
} else if( x < 0.0) {
assert y != 0.0;
failures += testStrictPowCase(x, y, f3(x, y));
failures += testNonstrictPowCase(x, y, f3ns(x, y));
continue;
} else {
// go to next iteration
expected = NaN;
continue;
}
failures += testPowCase(x, y, expected);
} // y
} // x
return failures;
}
static boolean equivalent(double a, double b) {
return Double.compare(a, b) == 0;
}
static double f1(double y) {
return (intClassify(y) == 1)?
Double.NEGATIVE_INFINITY:
Double.POSITIVE_INFINITY;
}
static double f2(double y) {
return (intClassify(y) == 1)?-0.0:0.0;
}
static double f3(double x, double y) {
switch( intClassify(y) ) {
case 0:
return StrictMath.pow(Math.abs(x), y);
// break;
case 1:
return -StrictMath.pow(Math.abs(x), y);
// break;
case -1:
return Double.NaN;
// break;
default:
throw new AssertionError("Bad classification.");
// break;
}
}
static double f3ns(double x, double y) {
switch( intClassify(y) ) {
case 0:
return Math.pow(Math.abs(x), y);
// break;
case 1:
return -Math.pow(Math.abs(x), y);
// break;
case -1:
return Double.NaN;
// break;
default:
throw new AssertionError("Bad classification.");
// break;
}
}
static boolean isFinite(double a) {
return (0.0*a == 0);
}
/**
* Return classification of argument: -1 for non-integers, 0 for
* even integers, 1 for odd integers.
*/
static int intClassify(double a) {
if(!isFinite(a) || // NaNs and infinities
(a != Math.floor(a) )) { // only integers are fixed-points of floor
return -1;
}
else {
// Determine if argument is an odd or even integer.
a = StrictMath.abs(a); // absolute value doesn't affect odd/even
if(a+1.0 == a) { // a > maximum odd floating-point integer
return 0; // Large integers are all even
}
else { // Convert double -> long and look at low-order bit
long ell = (long) a;
return ((ell & 0x1L) == (long)1)?1:0;
}
}
}
public static void main(String [] argv) {
int failures = 0;
failures += testPow();
failures += testCrossProduct();
if (failures > 0) {
System.err.println("Testing pow incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4101566 4831589
* @summary Check for correct implementation of Math.rint(double)
*
*/
import sun.misc.FpUtils;
import sun.misc.DoubleConsts;
public class Rint {
static int testRintCase(double input, double expected) {
int failures = 0;
double result;
failures += Tests.test("Math.rint", input, Math.rint(input), expected);
failures += Tests.test("Math.rint", -input, Math.rint(-input), -expected);
failures += Tests.test("StrictMath.rint",
input, StrictMath.rint(input), expected);
failures += Tests.test("StrictMath.rint", -input,
StrictMath.rint(-input), -expected);
return failures;
}
public static void main(String args[]) {
int failures = 0;
double twoToThe52 = FpUtils.scalb(1.0, 52); // 2^52
double [][] testCases = {
{0.0, 0.0},
{Double.MIN_VALUE, 0.0},
{FpUtils.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
{DoubleConsts.MIN_NORMAL, 0.0},
{0.2, 0.0},
{FpUtils.nextDown(0.5), 0.0},
{ 0.5, 0.0},
{ FpUtils.nextUp(0.5), 1.0},
{0.7, 1.0},
{FpUtils.nextDown(1.0), 1.0},
{ 1.0, 1.0},
{ FpUtils.nextUp(1.0), 1.0},
{FpUtils.nextDown(1.5), 1.0},
{ 1.5, 2.0},
{ FpUtils.nextUp(1.5), 2.0},
{4.2, 4.0},
{4.5, 4.0},
{4.7, 5.0},
{7.5, 8.0},
{7.2, 7.0},
{7.7, 8.0},
{150000.75, 150001.0},
{300000.5, 300000.0},
{FpUtils.nextUp(300000.5), 300001.0},
{FpUtils.nextDown(300000.75), 300001.0},
{300000.75, 300001.0},
{FpUtils.nextUp(300000.75), 300001.0},
{300000.99, 300001.0},
{262144.75, 262145.0}, //(2^18 ) + 0.75
{499998.75, 499999.0},
{524287.75, 524288.0}, //(2^19 -1) + 0.75
{524288.75, 524289.0},
{FpUtils.nextDown(twoToThe52), twoToThe52},
{twoToThe52, twoToThe52},
{FpUtils.nextUp(twoToThe52), FpUtils.nextUp(twoToThe52)},
{Double.MAX_VALUE, Double.MAX_VALUE},
{Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY},
{Double.NaN, Double.NaN}
};
for(int i = 0; i < testCases.length; i++) {
failures += testRintCase(testCases[i][0], testCases[i][1]);
}
// Test values throughout exponent range
for(double d = Double.MIN_VALUE;
d < Double.POSITIVE_INFINITY; d *= 2) {
failures += testRintCase(d, ((d<=0.5)?0.0:d));
}
if (failures > 0) {
System.err.println("Testing {Math, StrictMath}.rint incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5033578
* @summary Tests for {Math, StrictMath}.tan
* @compile -source 1.5 TanTests.java
* @run main TanTests
* @author Joseph D. Darcy
*/
public class TanTests {
private TanTests(){}
static int testTanCase(double input, double expected, double ulps) {
int failures = 0;
failures += Tests.testUlpDiff("StrictMath.tan(double, double)", input,
StrictMath.tan(input), expected, ulps);
failures += Tests.testUlpDiff("Math.tan(double, double)", input,
Math.tan(input), expected, ulps);
return failures;
}
static int testTan() {
int failures = 0;
double [][] testCases = {
// 1.1 ulp case from Gonnet
{0x1.31b97c4000001p24, -0x1.d08538b656222p34, 1.9},
// Remaining test cases adapted from work by Alex Liu
{0x1.be1b2d17ba207p6, -0x1.cf489c89f8066p49, 1.100000},
{0x1.e0a9e6ab97de7p7, 0x1.d31ce95f57459p50, 1.100000},
{0x1.23f8c5bcf003ep11, 0x1.f022585dbb50ap50, 1.100000},
{0x1.44bdb557e1dc1p20, 0x1.b67eaf362701fp49, 1.100000},
{0x1.604759040fb6fp68, 0x1.d574bc1f9e903p50, 1.100000},
{0x1.3d33fa4e5ba47p70, 0x1.ce1dd6e33fef8p49, 1.100000},
{0x1.f19e5d71b26bap85, 0x1.c2536a9119dd2p55, 1.100000},
{0x1.43ed062d2d62cp88, -0x1.c94b0c5b7b05p49, 1.100000},
{0x1.b7b895b030bep88, -0x1.cba9ebb0f20b9p51, 1.100000},
{0x1.a86090fe7c144p95, 0x1.d5ad72ca48bbfp48, 1.100000},
{0x1.d199df0700a61p95, -0x1.b8dd636f8dba7p49, 1.100000},
{0x1.d713037d1d222p106, -0x1.d57f035fd0146p48, 1.100000},
{0x1.ed1f6b066569bp115, 0x1.840af46cc9bep48, 1.100000},
{0x1.16800a51eff75p118, 0x1.c9f91caf08a6ap49, 1.100000},
{0x1.c1169c1040ecdp134, 0x1.e44a7eb56cb7p48, 1.100000},
{0x1.19b0fb40dddd5p145, -0x1.f1b1c235774b2p48, 1.100000},
{0x1.4d6b47f2480f8p162, 0x1.da1c2010795a5p51, 1.100000},
{0x1.682ff8e5429ddp163, -0x1.95a7aee1e93bep55, 1.100000},
{0x1.d0569fad9657dp204, -0x1.8f2ca17123aa5p49, 1.100000},
{0x1.55505de5bbc14p206, -0x1.e8d28e39ddf9p50, 1.100000},
{0x1.cf497083e6c77p206, -0x1.fd3fbaa40de18p49, 1.100000},
{0x1.c5b30c8686203p214, 0x1.f4d14469638a9p48, 1.100000},
{0x1.60d15b12ff0b7p217, 0x1.bc150932bd3d7p48, 1.100000},
{0x1.07cc6858d980bp218, -0x1.f3f7355c983a5p51, 1.100000},
{0x1.e06a67cd86969p218, 0x1.b0873124d98afp51, 1.100000},
{0x1.49704174c38e3p229, 0x1.e0301142ccbc2p49, 1.100000},
{0x1.ea19ceab3b06ap230, -0x1.fc22e687f0482p48, 1.100000},
{0x1.0c905503fea72p236, -0x1.7d4e9a45014d5p49, 1.100000},
{0x1.28eb1f8ddd7c3p257, -0x1.a951893680c71p49, 1.100000},
{0x1.310b11af2bfbep260, 0x1.84d458039c2e6p48, 1.100000},
{0x1.f3c172bb7afc2p265, -0x1.fb3139d3ba04fp49, 1.100000},
{0x1.54a28326cfedep267, 0x1.f416de8fb60bap53, 1.100000},
{0x1.5a5154d9d609dp269, -0x1.83d74cea8141p51, 1.100000},
{0x1.3ee75fd803b21p275, 0x1.b9ab67b61bf65p50, 1.100000},
{0x1.f4a4c781834d9p277, -0x1.d639ec63bf3b6p49, 1.100000},
{0x1.2053d5c14cf78p279, 0x1.fc31413372cdcp50, 1.100000},
{0x1.896d0a9acee4cp298, 0x1.f9136d6e27a5cp48, 1.100000},
{0x1.f010da08a862p302, -0x1.fd812c5e13483p49, 1.100000},
{0x1.65f2e272f729fp308, -0x1.f9f642ddaa32dp49, 1.100000},
{0x1.a8afbc4edb07dp309, 0x1.fa0d458320902p52, 1.100000},
{0x1.4d311a5447cdep329, -0x1.f7e98fe193e81p49, 1.100000},
{0x1.808f66338b21bp345, -0x1.bceaf45f61155p49, 1.100000},
{0x1.5a34aacf5ded1p350, 0x1.d41f0f13fadd4p49, 1.100000},
{0x1.3e8b85532bad1p354, -0x1.f0b21179d663ep49, 1.100000},
{0x1.1c2ecf01570acp394, -0x1.c215c9e2b7b24p49, 1.100000},
{0x1.666eba99d2837p402, 0x1.fbd5c4b527506p48, 1.100000},
{0x1.6cc39f07fafbbp460, -0x1.f087548a00e7cp49, 1.100000},
{0x1.9481228fea3ffp463, -0x1.c585e64ff44c8p48, 1.100000},
{0x1.79c3af0b4d0d4p466, 0x1.c9ed3716691f2p51, 1.100000},
{0x1.993ea84c3e23bp468, 0x1.a6b3954fc37f3p49, 1.100000},
{0x1.cfd6b13f64408p470, -0x1.f4db7cc2c09bp47, 1.100000},
{0x1.b820ccdd52299p473, 0x1.77a1ff863b0f3p52, 1.100000},
{0x1.157ef3a1528a5p475, -0x1.f4e14ddc45e49p51, 1.100000},
{0x1.b492a8997bc36p478, -0x1.e0db26b7f03e8p48, 1.100000},
{0x1.e0ea5674b831bp480, 0x1.e0ad6b3cdccdfp48, 1.100000},
{0x1.c62ac8b32cb9ep497, 0x1.c95d00a36f677p48, 1.100000},
{0x1.467f1daf12b43p498, 0x1.c6d3fdc096f0bp50, 1.100000},
{0x1.336e5a83e390cp502, 0x1.fc873dae28572p48, 1.100000},
{0x1.aaab1de0d6727p506, -0x1.e0482967d0354p49, 1.100000},
{0x1.e5ce06a12139cp507, 0x1.cea42e29735bdp49, 1.100000},
{0x1.87dad74d0dda8p516, -0x1.b2cde6c0a8b9fp48, 1.100000},
{0x1.e4feb94ee0989p524, -0x1.b227d0d0ffaa8p49, 1.100000},
{0x1.31c082b1361ebp525, 0x1.a7ed49158d736p49, 1.100000},
{0x1.56913865b3e16p531, 0x1.eeb7a32591c3bp52, 1.100000},
{0x1.36ade1fa883cap544, -0x1.fa087aadc0cbp48, 1.100000},
{0x1.de57314df4af8p559, 0x1.c686aa5a41075p49, 1.100000},
{0x1.0bb29bf7960ddp586, -0x1.d29ae1a3023cep50, 1.100000},
{0x1.049a584685941p588, -0x1.eebfb159dba67p51, 1.100000},
{0x1.33c1d4257b294p589, 0x1.ea1eedabea109p48, 1.100000},
{0x1.3587e511bf47bp590, 0x1.c897858ce0ca9p48, 1.100000},
{0x1.d12ee010c0facp590, 0x1.ab5b4b5065aa3p48, 1.100000},
{0x1.87bbed5af48d9p605, 0x1.f512c3b2be7cap50, 1.100000},
{0x1.a0b1131240cebp605, -0x1.fa373983fd571p48, 1.100000},
{0x1.116fdda1a04c9p616, -0x1.d76fdbc8552f3p51, 1.100000},
{0x1.67ebae833a034p620, 0x1.e1313af0a4075p50, 1.100000},
{0x1.9a50fbc5b0fecp627, 0x1.d89150884fbf7p50, 1.100000},
{0x1.6d625e0757e9cp631, -0x1.d0a5ecf002555p49, 1.100000},
{0x1.e880344cc9913p636, -0x1.fafd04caaf58bp48, 1.100000},
{0x1.e0a180b843cc5p650, 0x1.ea2aea3b8c953p49, 1.100000},
{0x1.fa91ce15157b2p652, 0x1.e6f5f4d47d83fp48, 1.100000},
{0x1.7696347caf8dfp654, 0x1.e0d36f2aef7dap51, 1.100000},
{0x1.886484b536161p666, -0x1.e3c96481e335bp51, 1.100000},
{0x1.0aa3ff2b41abdp675, -0x1.b3300ee04b4c8p50, 1.100000},
{0x1.d695ac08fe897p675, -0x1.c27fd21ecb13p51, 1.100000},
{0x1.4c1e532d7a99ap680, 0x1.e2ec695260c39p49, 1.100000},
{0x1.44a9f3e395802p685, -0x1.e7273ab9ce8e2p52, 1.100000},
{0x1.3a25ec2b43d45p697, -0x1.d23187ba6321ep49, 1.100000},
{0x1.96f5c2420c3fdp716, -0x1.ea06ab71ad719p49, 1.100000},
{0x1.926c063a9406bp741, 0x1.e3d3d9262fd66p48, 1.100000},
{0x1.1a57713d6fd93p754, -0x1.c10074d49490dp48, 1.100000},
{0x1.739387922e672p772, 0x1.bda527e215a3cp49, 1.100000},
{0x1.d286eff17f4d4p793, 0x1.d01c678ebfa1p49, 1.100000},
{0x1.f3d777206a062p794, -0x1.d8604b6d18385p49, 1.100000},
{0x1.ae91e6574da91p826, -0x1.fd1b26ab656c2p49, 1.100000},
{0x1.4422b3c871c9p836, 0x1.9d2cab1f3aebcp48, 1.100000},
{0x1.7ff8537071e1p840, 0x1.badde451c6ed7p48, 1.100000},
{0x1.c6fe9202e219dp845, -0x1.b2aa20745de3p51, 1.100000},
{0x1.a95a0b4015d88p846, 0x1.cdf5dfd045657p50, 1.100000},
{0x1.f823b9cff0daep867, 0x1.fd72fce3d5505p48, 1.100000},
{0x1.a6bee2afcd2fp886, 0x1.fe06265cd3aebp49, 1.100000},
{0x1.7b034b3412d17p892, 0x1.e48055812d391p50, 1.100000},
{0x1.58588f8cda276p894, 0x1.f806fddf0dd05p53, 1.100000},
{0x1.ce750a7963463p896, 0x1.e94f1f4018402p48, 1.100000},
{0x1.3d50a91fe82cfp897, 0x1.cd518fda10e95p48, 1.100000},
{0x1.f82dea1c0b809p897, -0x1.d6a0ef08179c5p48, 1.100000},
{0x1.38673e8c6a4afp903, 0x1.f4113a036478p48, 1.100000},
{0x1.dfb75e4a7432p911, 0x1.eb7bc6cb4d7f3p48, 1.100000},
{0x1.1230b975a72b3p916, -0x1.e1042be0759f9p48, 1.100000},
{0x1.302c2f5a4e6e5p916, 0x1.f66a9874cd60ap48, 1.100000},
{0x1.04e07a1d67b93p921, 0x1.87735139f6a0bp53, 1.100000},
{0x1.5a3eb79cd06fap931, -0x1.e00930c219ef3p51, 1.100000},
{0x1.8fb45679936fp937, 0x1.9a427588645c4p50, 1.100000},
{0x1.c4abb225260c6p964, -0x1.d1e64e91ac6ap50, 1.100000},
{0x1.b43e449b25382p982, -0x1.f1848cc5ac4fep50, 1.100000},
{0x1.504d9d7179b1ap983, 0x1.a4e51ea807786p48, 1.100000},
{0x1.83a5af80fb39bp987, 0x1.a6dde6c2220ebp48, 1.100000},
{0x1.5d978d9ad84c8p1011, 0x1.ec96900bfd1ddp51, 1.100000},
};
for(double[] testCase: testCases) {
failures += testTanCase(testCase[0], testCase[1], testCase[2]);
}
return failures;
}
public static void main(String [] argv) {
int failures = 0;
failures += testTan();
if (failures > 0) {
System.err.println("Testing tan incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* Shared static test methods for numerical tests. Sharing these
* helper test methods avoids repeated functions in the various test
* programs. The test methods return 1 for a test failure and 0 for
* success. The order of arguments to the test methods is generally
* the test name, followed by the test arguments, the computed result,
* and finally the expected result.
*/
import sun.misc.FpUtils;
public class Tests {
private Tests(){}; // do not instantiate
private static String toHexString(float f) {
if (!Float.isNaN(f))
return Float.toHexString(f);
else
return "NaN(0x" + Integer.toHexString(Float.floatToRawIntBits(f)) + ")";
}
private static String toHexString(double d) {
if (!Double.isNaN(d))
return Double.toHexString(d);
else
return "NaN(0x" + Long.toHexString(Double.doubleToRawLongBits(d)) + ")";
}
public static int test(String testName, float input,
boolean result, boolean expected) {
if (expected != result) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\n" +
"\tgot " + result + ").");
return 1;
}
else
return 0;
}
public static int test(String testName, double input,
boolean result, boolean expected) {
if (expected != result) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\n" +
"\tgot " + result + ").");
return 1;
}
else
return 0;
}
public static int test(String testName, float input1, float input2,
boolean result, boolean expected) {
if (expected != result) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor inputs " + input1 + "\t(" + toHexString(input1) + ") and "
+ input2 + "\t(" + toHexString(input2) + ")\n" +
"\texpected " + expected + "\n" +
"\tgot " + result + ").");
return 1;
}
return 0;
}
public static int test(String testName, double input1, double input2,
boolean result, boolean expected) {
if (expected != result) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor inputs " + input1 + "\t(" + toHexString(input1) + ") and "
+ input2 + "\t(" + toHexString(input2) + ")\n" +
"\texpected " + expected + "\n" +
"\tgot " + result + ").");
return 1;
}
return 0;
}
public static int test(String testName, float input,
int result, int expected) {
if (expected != result) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\n" +
"\tgot " + result + ").");
return 1;
}
return 0;
}
public static int test(String testName, double input,
int result, int expected) {
if (expected != result) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\n" +
"\tgot " + result + ").");
return 1;
}
else
return 0;
}
public static int test(String testName, float input,
float result, float expected) {
if (Float.compare(expected, result) != 0 ) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ").");
return 1;
}
else
return 0;
}
public static int test(String testName, double input,
double result, double expected) {
if (Double.compare(expected, result ) != 0) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ").");
return 1;
}
else
return 0;
}
public static int test(String testName,
float input1, double input2,
float result, float expected) {
if (Float.compare(expected, result ) != 0) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor inputs " + input1 + "\t(" + toHexString(input1) + ") and "
+ input2 + "\t(" + toHexString(input2) + ")\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ").");
return 1;
}
else
return 0;
}
public static int test(String testName,
double input1, double input2,
double result, double expected) {
if (Double.compare(expected, result ) != 0) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor inputs " + input1 + "\t(" + toHexString(input1) + ") and "
+ input2 + "\t(" + toHexString(input2) + ")\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ").");
return 1;
}
else
return 0;
}
public static int test(String testName,
float input1, int input2,
float result, float expected) {
if (Float.compare(expected, result ) != 0) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor inputs " + input1 + "\t(" + toHexString(input1) + ") and "
+ input2 + "\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ").");
return 1;
}
else
return 0;
}
public static int test(String testName,
double input1, int input2,
double result, double expected) {
if (Double.compare(expected, result ) != 0) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor inputs " + input1 + "\t(" + toHexString(input1) + ") and "
+ input2 + "\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ").");
return 1;
}
else
return 0;
}
static int testUlpCore(double result, double expected, double ulps) {
// We assume we won't be unlucky and have an inexact expected
// be nextDown(2^i) when 2^i would be the correctly rounded
// answer. This would cause the ulp size to be half as large
// as it should be, doubling the measured error).
if (Double.compare(expected, result) == 0) {
return 0; // result and expected are equivalent
} else {
if( ulps == 0.0) {
// Equivalent results required but not found
return 1;
} else {
double difference = expected - result;
if (FpUtils.isUnordered(expected, result) ||
Double.isNaN(difference) ||
// fail if greater than or unordered
!(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
return 1;
}
else
return 0;
}
}
}
// One input argument.
public static int testUlpDiff(String testName, double input,
double result, double expected, double ulps) {
int code = testUlpCore(result, expected, ulps);
if (code == 1) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ");\n" +
"\tdifference greater than ulp tolerance " + ulps);
}
return code;
}
// Two input arguments.
public static int testUlpDiff(String testName, double input1, double input2,
double result, double expected, double ulps) {
int code = testUlpCore(result, expected, ulps);
if (code == 1) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor inputs " + input1 + "\t(" + toHexString(input1) + ") and "
+ input2 + "\t(" + toHexString(input2) + ")\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ");\n" +
"\tdifference greater than ulp tolerance " + ulps);
}
return code;
}
// For a successful test, the result must be within the ulp bound of
// expected AND the result must have absolute value less than or
// equal to absBound.
public static int testUlpDiffWithAbsBound(String testName, double input,
double result, double expected,
double ulps, double absBound) {
int code = 0; // return code value
if (!(StrictMath.abs(result) <= StrictMath.abs(absBound)) &&
!Double.isNaN(expected)) {
code = 1;
} else
code = testUlpCore(result, expected, ulps);
if (code == 1) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ");\n" +
"\tdifference greater than ulp tolerance " + ulps +
" or the result has larger magnitude than " + absBound);
}
return code;
}
// For a successful test, the result must be within the ulp bound of
// expected AND the result must have absolute value greater than
// or equal to the lowerBound.
public static int testUlpDiffWithLowerBound(String testName, double input,
double result, double expected,
double ulps, double lowerBound) {
int code = 0; // return code value
if (!(result >= lowerBound) && !Double.isNaN(expected)) {
code = 1;
} else
code = testUlpCore(result, expected, ulps);
if (code == 1) {
System.err.println("Failure for " + testName +
":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")" +
"\n\texpected " + expected + "\t(" + toHexString(expected) + ")" +
"\n\tgot " + result + "\t(" + toHexString(result) + ");" +
"\ndifference greater than ulp tolerance " + ulps +
" or result not greater than or equal to the bound " + lowerBound);
}
return code;
}
public static int testTolerance(String testName, double input,
double result, double expected, double tolerance) {
if (Double.compare(expected, result ) != 0) {
double difference = expected - result;
if (FpUtils.isUnordered(expected, result) ||
Double.isNaN(difference) ||
// fail if greater than or unordered
!(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + toHexString(input) + ")\n" +
"\texpected " + expected + "\t(" + toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + toHexString(result) + ");\n" +
"\tdifference greater than tolerance 10^-" + tolerance);
return 1;
}
return 0;
}
else
return 0;
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4495754
* @summary Basic test for int byte swap code on short and char
* @author Josh Bloch
*/
public class ByteSwap {
public static void main(String args[]) {
if (Short.reverseBytes((short)0xaabb) != (short)0xbbaa)
throw new RuntimeException("short");
if (Character.reverseBytes((char)0xaabb) != (char)0xbbaa)
throw new RuntimeException("char");
}
}
/*
* Copyright 1998-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4136371 5017980 6576055
* @summary Test Short.decode method
* @author madbot
* @author Joseph D. Darcy
*/
/**
* There are six methods in java.lang.Short which transform strings
* into a short or Short value:
*
* public Short(String s)
* public static Short decode(String nm)
* public static short parseShort(String s, int radix)
* public static short parseShort(String s)
* public static Short valueOf(String s, int radix)
* public static Short valueOf(String s)
*
* However, of these only decode has a nontrivial implementation
* in that class.
*/
public class Decode {
private static void check(String ashort, short expected) {
short sh = (Short.decode(ashort)).shortValue();
if (sh != expected)
throw new RuntimeException("Short.decode failed. String:" +
ashort + " Result:" + sh);
}
private static void checkFailure(String val, String message) {
try {
short n = (Short.decode(val)).shortValue();
throw new RuntimeException(message);
} catch (NumberFormatException e) { /* Okay */}
}
public static void main(String[] args) throws Exception {
check(new String(""+Short.MIN_VALUE), Short.MIN_VALUE);
check(new String(""+Short.MAX_VALUE), Short.MAX_VALUE);
check("10", (short)10);
check("0x10", (short)16);
check("0X10", (short)16);
check("010", (short)8);
check("#10", (short)16);
check("+10", (short)10);
check("+0x10", (short)16);
check("+0X10", (short)16);
check("+010", (short)8);
check("+#10", (short)16);
check("-10", (short)-10);
check("-0x10", (short)-16);
check("-0X10", (short)-16);
check("-010", (short)-8);
check("-#10", (short)-16);
check(Integer.toString((int)Short.MIN_VALUE), Short.MIN_VALUE);
check(Integer.toString((int)Short.MAX_VALUE), Short.MAX_VALUE);
checkFailure("0x-10", "Short.decode allows negative sign in wrong position.");
checkFailure("0x+10", "Short.decode allows positive sign in wrong position.");
checkFailure("+", "Raw plus sign allowed.");
checkFailure("-", "Raw minus sign allowed.");
checkFailure(Integer.toString((int)Short.MIN_VALUE - 1), "Out of range");
checkFailure(Integer.toString((int)Short.MAX_VALUE + 1), "Out of range");
checkFailure("", "Empty String");
}
}
/*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4347132
* @summary Tests specifically for StrictMath.cbrt
* @author Joseph D. Darcy
*/
/**
* The tests in ../Math/CubeRootTests.java test properties that should
* hold for any cube root implementation, including the FDLIBM-based
* one required for StrictMath.cbrt. Therefore, the test cases in
* ../Math/CubeRootTests.java are run against both the Math and
* StrictMath versions of cube root. The role of this test is to
* verify that the FDLIBM cbrt algorithm is being used by running
* golden file tests on values that may vary from one conforming cube
* root implementation to another.
*/
public class CubeRootTests {
private CubeRootTests(){}
static int testCubeRootCase(double input, double expected) {
int failures=0;
double minus_input = -input;
double minus_expected = -expected;
failures+=Tests.test("StrictMath.cbrt(double)", input,
StrictMath.cbrt(input), expected);
failures+=Tests.test("StrictMath.cbrt(double)", minus_input,
StrictMath.cbrt(minus_input), minus_expected);
return failures;
}
static int testCubeRoot() {
int failures = 0;
double [][] testCases = {
{0x1.ffffffffffffep-766, 0x1.fffffffffffffp-256},
{0x1.ffffffffffffep-763, 0x1.fffffffffffffp-255},
{0x1.ffffffffffffep-760, 0x1.fffffffffffffp-254},
{0x1.ffffffffffffep-757, 0x1.fffffffffffffp-253},
{0x1.ffffffffffffep-754, 0x1.fffffffffffffp-252},
{0x1.ffffffffffffep-751, 0x1.fffffffffffffp-251},
{0x1.ffffffffffffep-748, 0x1.fffffffffffffp-250},
{0x1.ffffffffffffep-745, 0x1.fffffffffffffp-249},
{0x1.ffffffffffffep-742, 0x1.fffffffffffffp-248},
{0x1.ffffffffffffep-739, 0x1.fffffffffffffp-247},
{0x1.ffffffffffffep-1006, 0x1.fffffffffffffp-336},
{0x1.ffffffffffffep-736, 0x1.fffffffffffffp-246},
{0x1.ffffffffffffep-733, 0x1.fffffffffffffp-245},
{0x1.ffffffffffffep-730, 0x1.fffffffffffffp-244},
{0x1.ffffffffffffep-727, 0x1.fffffffffffffp-243},
{0x1.ffffffffffffep-724, 0x1.fffffffffffffp-242},
{0x1.ffffffffffffep-721, 0x1.fffffffffffffp-241},
{0x1.ffffffffffffep-718, 0x1.fffffffffffffp-240},
{0x1.ffffffffffffep-715, 0x1.fffffffffffffp-239},
{0x1.ffffffffffffep-712, 0x1.fffffffffffffp-238},
{0x1.ffffffffffffep-709, 0x1.fffffffffffffp-237},
{0x1.ffffffffffffep-706, 0x1.fffffffffffffp-236},
{0x1.ffffffffffffep-703, 0x1.fffffffffffffp-235},
{0x1.ffffffffffffep-700, 0x1.fffffffffffffp-234},
{0x1.ffffffffffffep-697, 0x1.fffffffffffffp-233},
{0x1.ffffffffffffep-694, 0x1.fffffffffffffp-232},
{0x1.ffffffffffffep-691, 0x1.fffffffffffffp-231},
{0x1.ffffffffffffep-1003, 0x1.fffffffffffffp-335},
{0x1.ffffffffffffep-688, 0x1.fffffffffffffp-230},
{0x1.ffffffffffffep-685, 0x1.fffffffffffffp-229},
{0x1.ffffffffffffep-682, 0x1.fffffffffffffp-228},
{0x1.ffffffffffffep-679, 0x1.fffffffffffffp-227},
{0x1.ffffffffffffep-676, 0x1.fffffffffffffp-226},
{0x1.ffffffffffffep-673, 0x1.fffffffffffffp-225},
{0x1.ffffffffffffep-670, 0x1.fffffffffffffp-224},
{0x1.ffffffffffffep-667, 0x1.fffffffffffffp-223},
{0x1.ffffffffffffep-664, 0x1.fffffffffffffp-222},
{0x1.ffffffffffffep-661, 0x1.fffffffffffffp-221},
{0x1.ffffffffffffep-658, 0x1.fffffffffffffp-220},
{0x1.ffffffffffffep-655, 0x1.fffffffffffffp-219},
{0x1.ffffffffffffep-652, 0x1.fffffffffffffp-218},
{0x1.ffffffffffffep-649, 0x1.fffffffffffffp-217},
{0x1.ffffffffffffep-646, 0x1.fffffffffffffp-216},
{0x1.ffffffffffffep-643, 0x1.fffffffffffffp-215},
{0x1.ffffffffffffep-1000, 0x1.fffffffffffffp-334},
{0x1.ffffffffffffep-640, 0x1.fffffffffffffp-214},
{0x1.ffffffffffffep-637, 0x1.fffffffffffffp-213},
{0x1.ffffffffffffep-634, 0x1.fffffffffffffp-212},
{0x1.ffffffffffffep-631, 0x1.fffffffffffffp-211},
{0x1.ffffffffffffep-628, 0x1.fffffffffffffp-210},
{0x1.ffffffffffffep-625, 0x1.fffffffffffffp-209},
{0x1.ffffffffffffep-622, 0x1.fffffffffffffp-208},
{0x1.ffffffffffffep-619, 0x1.fffffffffffffp-207},
{0x1.ffffffffffffep-616, 0x1.fffffffffffffp-206},
{0x1.ffffffffffffep-613, 0x1.fffffffffffffp-205},
{0x1.ffffffffffffep-610, 0x1.fffffffffffffp-204},
{0x1.ffffffffffffep-607, 0x1.fffffffffffffp-203},
{0x1.ffffffffffffep-604, 0x1.fffffffffffffp-202},
{0x1.ffffffffffffep-601, 0x1.fffffffffffffp-201},
{0x1.ffffffffffffep-598, 0x1.fffffffffffffp-200},
{0x1.ffffffffffffep-595, 0x1.fffffffffffffp-199},
{0x1.ffffffffffffep-997, 0x1.fffffffffffffp-333},
{0x1.ffffffffffffep-592, 0x1.fffffffffffffp-198},
{0x1.ffffffffffffep-589, 0x1.fffffffffffffp-197},
{0x1.ffffffffffffep-586, 0x1.fffffffffffffp-196},
{0x1.ffffffffffffep-583, 0x1.fffffffffffffp-195},
{0x1.ffffffffffffep-580, 0x1.fffffffffffffp-194},
{0x1.ffffffffffffep-577, 0x1.fffffffffffffp-193},
{0x1.ffffffffffffep-574, 0x1.fffffffffffffp-192},
{0x1.ffffffffffffep-571, 0x1.fffffffffffffp-191},
{0x1.ffffffffffffep-568, 0x1.fffffffffffffp-190},
{0x1.ffffffffffffep-565, 0x1.fffffffffffffp-189},
{0x1.ffffffffffffep-562, 0x1.fffffffffffffp-188},
{0x1.ffffffffffffep-559, 0x1.fffffffffffffp-187},
{0x1.ffffffffffffep-556, 0x1.fffffffffffffp-186},
{0x1.ffffffffffffep-553, 0x1.fffffffffffffp-185},
{0x1.ffffffffffffep-550, 0x1.fffffffffffffp-184},
{0x1.ffffffffffffep-547, 0x1.fffffffffffffp-183},
{0x1.ffffffffffffep-994, 0x1.fffffffffffffp-332},
{0x1.ffffffffffffep-544, 0x1.fffffffffffffp-182},
{0x1.ffffffffffffep-541, 0x1.fffffffffffffp-181},
{0x1.ffffffffffffep-538, 0x1.fffffffffffffp-180},
{0x1.ffffffffffffep-535, 0x1.fffffffffffffp-179},
{0x1.ffffffffffffep-532, 0x1.fffffffffffffp-178},
{0x1.ffffffffffffep-529, 0x1.fffffffffffffp-177},
{0x0.00000000001fp-1022, 0x1.fa9c313858568p-356},
{0x1.ffffffffffffep-526, 0x1.fffffffffffffp-176},
{0x1.ffffffffffffep-523, 0x1.fffffffffffffp-175},
{0x1.ffffffffffffep-520, 0x1.fffffffffffffp-174},
{0x1.ffffffffffffep-517, 0x1.fffffffffffffp-173},
{0x0.00000000001fdp-1022, 0x1.feff7f94ea34dp-356},
{0x1.ffffffffffffep-514, 0x1.fffffffffffffp-172},
{0x0.00000001fffe7p-1022, 0x1.ffff7aaa87f1bp-352},
{0x0.00000001fffffp-1022, 0x1.fffffaaaaa9c7p-352},
{0x0.00001ffffff4p-1022, 0x1.ffffffcp-348},
{0x0.00001ffffffffp-1022, 0x1.ffffffffaaaabp-348},
{0x0.01ffffffffffcp-1022, 0x1.ffffffffffeabp-344},
{0x1.ffffffffffffep-511, 0x1.fffffffffffffp-171},
{0x1.ffffffffffffep-508, 0x1.fffffffffffffp-170},
{0x1.ffffffffffffep-505, 0x1.fffffffffffffp-169},
{0x1.ffffffffffffep-502, 0x1.fffffffffffffp-168},
{0x1.ffffffffffffep-499, 0x1.fffffffffffffp-167},
{0x1.ffffffffffffep-991, 0x1.fffffffffffffp-331},
{0x1.ffffffffffffep-496, 0x1.fffffffffffffp-166},
{0x1.ffffffffffffep-493, 0x1.fffffffffffffp-165},
{0x1.ffffffffffffep-490, 0x1.fffffffffffffp-164},
{0x1.ffffffffffffep-487, 0x1.fffffffffffffp-163},
{0x1.ffffffffffffep-484, 0x1.fffffffffffffp-162},
{0x1.ffffffffffffep-481, 0x1.fffffffffffffp-161},
{0x1.ffffffffffffep-478, 0x1.fffffffffffffp-160},
{0x1.ffffffffffffep-475, 0x1.fffffffffffffp-159},
{0x1.ffffffffffffep-472, 0x1.fffffffffffffp-158},
{0x1.ffffffffffffep-469, 0x1.fffffffffffffp-157},
{0x1.ffffffffffffep-466, 0x1.fffffffffffffp-156},
{0x1.ffffffffffffep-463, 0x1.fffffffffffffp-155},
{0x1.ffffffffffffep-460, 0x1.fffffffffffffp-154},
{0x1.ffffffffffffep-457, 0x1.fffffffffffffp-153},
{0x1.ffffffffffffep-454, 0x1.fffffffffffffp-152},
{0x1.ffffffffffffep-451, 0x1.fffffffffffffp-151},
{0x1.ffffffffffffep-988, 0x1.fffffffffffffp-330},
{0x1.ffffffffffffep-448, 0x1.fffffffffffffp-150},
{0x1.ffffffffffffep-445, 0x1.fffffffffffffp-149},
{0x1.ffffffffffffep-442, 0x1.fffffffffffffp-148},
{0x1.ffffffffffffep-439, 0x1.fffffffffffffp-147},
{0x1.ffffffffffffep-436, 0x1.fffffffffffffp-146},
{0x1.ffffffffffffep-433, 0x1.fffffffffffffp-145},
{0x1.ffffffffffffep-430, 0x1.fffffffffffffp-144},
{0x1.ffffffffffffep-427, 0x1.fffffffffffffp-143},
{0x1.ffffffffffffep-424, 0x1.fffffffffffffp-142},
{0x1.ffffffffffffep-421, 0x1.fffffffffffffp-141},
{0x1.ffffffffffffep-418, 0x1.fffffffffffffp-140},
{0x1.ffffffffffffep-415, 0x1.fffffffffffffp-139},
{0x1.ffffffffffffep-412, 0x1.fffffffffffffp-138},
{0x1.ffffffffffffep-409, 0x1.fffffffffffffp-137},
{0x1.ffffffffffffep-406, 0x1.fffffffffffffp-136},
{0x1.ffffffffffffep-403, 0x1.fffffffffffffp-135},
{0x1.ffffffffffffep-985, 0x1.fffffffffffffp-329},
{0x1.ffffffffffffep-400, 0x1.fffffffffffffp-134},
{0x1.ffffffffffffep-397, 0x1.fffffffffffffp-133},
{0x1.ffffffffffffep-394, 0x1.fffffffffffffp-132},
{0x1.ffffffffffffep-391, 0x1.fffffffffffffp-131},
{0x1.ffffffffffffep-388, 0x1.fffffffffffffp-130},
{0x1.ffffffffffffep-385, 0x1.fffffffffffffp-129},
{0x1.ffffffffffffep-382, 0x1.fffffffffffffp-128},
{0x1.ffffffffffffep-379, 0x1.fffffffffffffp-127},
{0x1.ffffffffffffep-376, 0x1.fffffffffffffp-126},
{0x1.ffffffffffffep-373, 0x1.fffffffffffffp-125},
{0x1.ffffffffffffep-370, 0x1.fffffffffffffp-124},
{0x1.ffffffffffffep-367, 0x1.fffffffffffffp-123},
{0x1.ffffffffffffep-364, 0x1.fffffffffffffp-122},
{0x1.ffffffffffffep-361, 0x1.fffffffffffffp-121},
{0x1.ffffffffffffep-358, 0x1.fffffffffffffp-120},
{0x1.ffffffffffffep-355, 0x1.fffffffffffffp-119},
{0x1.ffffffffffffep-982, 0x1.fffffffffffffp-328},
{0x1.ffffffffffffep-352, 0x1.fffffffffffffp-118},
{0x1.ffffffffffffep-349, 0x1.fffffffffffffp-117},
{0x1.ffffffffffffep-346, 0x1.fffffffffffffp-116},
{0x1.ffffffffffffep-343, 0x1.fffffffffffffp-115},
{0x1.ffffffffffffep-340, 0x1.fffffffffffffp-114},
{0x1.ffffffffffffep-337, 0x1.fffffffffffffp-113},
{0x1.ffffffffffffep-334, 0x1.fffffffffffffp-112},
{0x1.ffffffffffffep-331, 0x1.fffffffffffffp-111},
{0x1.ffffffffffffep-328, 0x1.fffffffffffffp-110},
{0x1.ffffffffffffep-325, 0x1.fffffffffffffp-109},
{0x1.ffffffffffffep-322, 0x1.fffffffffffffp-108},
{0x1.ffffffffffffep-319, 0x1.fffffffffffffp-107},
{0x1.ffffffffffffep-316, 0x1.fffffffffffffp-106},
{0x1.ffffffffffffep-313, 0x1.fffffffffffffp-105},
{0x1.ffffffffffffep-310, 0x1.fffffffffffffp-104},
{0x1.ffffffffffffep-307, 0x1.fffffffffffffp-103},
{0x1.ffffffffffffep-979, 0x1.fffffffffffffp-327},
{0x1.ffffffffffffep-304, 0x1.fffffffffffffp-102},
{0x1.ffffffffffffep-301, 0x1.fffffffffffffp-101},
{0x1.ffffffffffffep-298, 0x1.fffffffffffffp-100},
{0x1.ffffffffffffep-295, 0x1.fffffffffffffp-99},
{0x1.ffffffffffffep-292, 0x1.fffffffffffffp-98},
{0x1.ffffffffffffep-289, 0x1.fffffffffffffp-97},
{0x1.ffffffffffffep-286, 0x1.fffffffffffffp-96},
{0x1.ffffffffffffep-283, 0x1.fffffffffffffp-95},
{0x1.ffffffffffffep-280, 0x1.fffffffffffffp-94},
{0x1.ffffffffffffep-277, 0x1.fffffffffffffp-93},
{0x1.ffffffffffffep-274, 0x1.fffffffffffffp-92},
{0x1.ffffffffffffep-271, 0x1.fffffffffffffp-91},
{0x1.ffffffffffffep-268, 0x1.fffffffffffffp-90},
{0x1.ffffffffffffep-265, 0x1.fffffffffffffp-89},
{0x1.ffffffffffffep-262, 0x1.fffffffffffffp-88},
{0x1.ffffffffffffep-259, 0x1.fffffffffffffp-87},
{0x1.ffffffffffffep-1021, 0x1.fffffffffffffp-341},
{0x1.ffffffffffffep-976, 0x1.fffffffffffffp-326},
{0x1.ffffffffffffep-256, 0x1.fffffffffffffp-86},
{0x1.ffffffffffffep-253, 0x1.fffffffffffffp-85},
{0x1.ffffffffffffep-250, 0x1.fffffffffffffp-84},
{0x1.ffffffffffffep-247, 0x1.fffffffffffffp-83},
{0x1.ffffffffffffep-244, 0x1.fffffffffffffp-82},
{0x1.ffffffffffffep-241, 0x1.fffffffffffffp-81},
{0x1.ffffffffffffep-238, 0x1.fffffffffffffp-80},
{0x1.ffffffffffffep-235, 0x1.fffffffffffffp-79},
{0x1.ffffffffffffep-232, 0x1.fffffffffffffp-78},
{0x1.ffffffffffffep-229, 0x1.fffffffffffffp-77},
{0x1.ffffffffffffep-226, 0x1.fffffffffffffp-76},
{0x1.ffffffffffffep-223, 0x1.fffffffffffffp-75},
{0x1.ffffffffffffep-220, 0x1.fffffffffffffp-74},
{0x1.ffffffffffffep-217, 0x1.fffffffffffffp-73},
{0x1.ffffffffffffep-214, 0x1.fffffffffffffp-72},
{0x1.ffffffffffffep-211, 0x1.fffffffffffffp-71},
{0x1.ffffffffffffep-973, 0x1.fffffffffffffp-325},
{0x1.ffffffffffffep-208, 0x1.fffffffffffffp-70},
{0x1.ffffffffffffep-205, 0x1.fffffffffffffp-69},
{0x1.ffffffffffffep-202, 0x1.fffffffffffffp-68},
{0x1.ffffffffffffep-199, 0x1.fffffffffffffp-67},
{0x1.ffffffffffffep-196, 0x1.fffffffffffffp-66},
{0x1.ffffffffffffep-193, 0x1.fffffffffffffp-65},
{0x1.ffffffffffffep-190, 0x1.fffffffffffffp-64},
{0x1.ffffffffffffep-187, 0x1.fffffffffffffp-63},
{0x1.ffffffffffffep-184, 0x1.fffffffffffffp-62},
{0x1.ffffffffffffep-181, 0x1.fffffffffffffp-61},
{0x1.ffffffffffffep-178, 0x1.fffffffffffffp-60},
{0x1.ffffffffffffep-175, 0x1.fffffffffffffp-59},
{0x1.ffffffffffffep-172, 0x1.fffffffffffffp-58},
{0x1.ffffffffffffep-169, 0x1.fffffffffffffp-57},
{0x1.ffffffffffffep-166, 0x1.fffffffffffffp-56},
{0x1.ffffffffffffep-163, 0x1.fffffffffffffp-55},
{0x1.ffffffffffffep-970, 0x1.fffffffffffffp-324},
{0x1.ffffffffffffep-160, 0x1.fffffffffffffp-54},
{0x1.ffffffffffffep-157, 0x1.fffffffffffffp-53},
{0x1.ffffffffffffep-154, 0x1.fffffffffffffp-52},
{0x1.ffffffffffffep-151, 0x1.fffffffffffffp-51},
{0x1.ffffffffffffep-148, 0x1.fffffffffffffp-50},
{0x1.ffffffffffffep-145, 0x1.fffffffffffffp-49},
{0x1.ffffffffffffep-142, 0x1.fffffffffffffp-48},
{0x1.ffffffffffffep-139, 0x1.fffffffffffffp-47},
{0x1.ffffffffffffep-136, 0x1.fffffffffffffp-46},
{0x1.ffffffffffffep-133, 0x1.fffffffffffffp-45},
{0x1.ffffffffffffep-130, 0x1.fffffffffffffp-44},
{0x1.ffffffffffffep-127, 0x1.fffffffffffffp-43},
{0x1.ffffffffffffep-124, 0x1.fffffffffffffp-42},
{0x1.ffffffffffffep-121, 0x1.fffffffffffffp-41},
{0x1.ffffffffffffep-118, 0x1.fffffffffffffp-40},
{0x1.ffffffffffffep-115, 0x1.fffffffffffffp-39},
{0x1.ffffffffffffep-967, 0x1.fffffffffffffp-323},
{0x1.ffffffffffffep-112, 0x1.fffffffffffffp-38},
{0x1.ffffffffffffep-109, 0x1.fffffffffffffp-37},
{0x1.ffffffffffffep-106, 0x1.fffffffffffffp-36},
{0x1.ffffffffffffep-103, 0x1.fffffffffffffp-35},
{0x1.ffffffffffffep-100, 0x1.fffffffffffffp-34},
{0x1.ffffffffffffep-97, 0x1.fffffffffffffp-33},
{0x1.ffffffffffffep-94, 0x1.fffffffffffffp-32},
{0x1.ffffffffffffep-91, 0x1.fffffffffffffp-31},
{0x1.ffffffffffffep-88, 0x1.fffffffffffffp-30},
{0x1.ffffffffffffep-85, 0x1.fffffffffffffp-29},
{0x1.ffffffffffffep-82, 0x1.fffffffffffffp-28},
{0x1.ffffffffffffep-79, 0x1.fffffffffffffp-27},
{0x1.ffffffffffffep-76, 0x1.fffffffffffffp-26},
{0x1.ffffffffffffep-73, 0x1.fffffffffffffp-25},
{0x1.ffffffffffffep-70, 0x1.fffffffffffffp-24},
{0x1.ffffffffffffep-67, 0x1.fffffffffffffp-23},
{0x1.ffffffffffffep-964, 0x1.fffffffffffffp-322},
{0x1.ffffffffffffep-64, 0x1.fffffffffffffp-22},
{0x1.ffffffffffffep-61, 0x1.fffffffffffffp-21},
{0x1.ffffffffffffep-58, 0x1.fffffffffffffp-20},
{0x1.ffffffffffffep-55, 0x1.fffffffffffffp-19},
{0x1.ffffffffffffep-52, 0x1.fffffffffffffp-18},
{0x1.ffffffffffffep-49, 0x1.fffffffffffffp-17},
{0x1.ffffffffffffep-46, 0x1.fffffffffffffp-16},
{0x1.ffffffffffffep-43, 0x1.fffffffffffffp-15},
{0x1.ffffffffffffep-40, 0x1.fffffffffffffp-14},
{0x1.ffffffffffffep-37, 0x1.fffffffffffffp-13},
{0x1.ffffffffffffep-34, 0x1.fffffffffffffp-12},
{0x1.ffffffffffffep-31, 0x1.fffffffffffffp-11},
{0x1.ffffffffffffep-28, 0x1.fffffffffffffp-10},
{0x1.ffffffffffffep-25, 0x1.fffffffffffffp-9},
{0x1.ffffffffffffep-22, 0x1.fffffffffffffp-8},
{0x0.000000000003ep-1022, 0x1.fa9c313858568p-357},
{0x1.ffffffffffffep-19, 0x1.fffffffffffffp-7},
{0x1.ffffffffffffep-961, 0x1.fffffffffffffp-321},
{0x1.ffffffffffffep-16, 0x1.fffffffffffffp-6},
{0x1.ffffffffffffep-13, 0x1.fffffffffffffp-5},
{0x1.ffffffffffffep-10, 0x1.fffffffffffffp-4},
{0x1.ffffffffffffep-7, 0x1.fffffffffffffp-3},
{0x0.000000000003fp-1022, 0x1.fd51bf2069fe6p-357},
{0x1.ffffffffffffep-4, 0x1.fffffffffffffp-2},
{0x1.ffffffffffffep-1, 0x1.fffffffffffffp-1},
{0x0.000000003fffcp-1022, 0x1.ffff55551c71bp-353},
{0x0.000003fffffe8p-1022, 0x1.ffffffcp-349},
{0x0.000003ffffffcp-1022, 0x1.fffffff555555p-349},
{0x0.003fffffffff9p-1022, 0x1.fffffffffed55p-345},
{0x1.ffffffffffffep2, 0x1.fffffffffffffp0},
{0x1.bp4, 0x1.8p1},
{0x1.ffffffffffffep5, 0x1.fffffffffffffp1},
{0x1.f3ffffffffff4p6, 0x1.3fffffffffffep2},
{0x1.f3ffffffffffcp6, 0x1.3ffffffffffffp2},
{0x1.bp7, 0x1.8p2},
{0x1.56ffffffffffep8, 0x1.bffffffffffffp2},
{0x1.ffffffffffffep8, 0x1.fffffffffffffp2},
{0x1.6c8p9, 0x1.2p3},
{0x1.f3ffffffffff4p9, 0x1.3fffffffffffep3},
{0x1.f3ffffffffffcp9, 0x1.3ffffffffffffp3},
{0x1.4cbfffffffffcp10, 0x1.5fffffffffffep3},
{0x1.4cbfffffffffep10, 0x1.5ffffffffffffp3},
{0x1.bp10, 0x1.8p3},
{0x1.129ffffffffa4p11, 0x1.9ffffffffffd1p3},
{0x1.129fffffffffep11, 0x1.9ffffffffffffp3},
{0x1.56ffffffffffep11, 0x1.bffffffffffffp3},
{0x1.a5ep11, 0x1.ep3},
{0x1.ffffffffffffep11, 0x1.fffffffffffffp3},
{0x1.330fffffffc1ep12, 0x1.0fffffffffedbp4},
{0x1.331p12, 0x1.1p4},
{0x1.6c8p12, 0x1.2p4},
{0x1.acafffffffffap12, 0x1.2ffffffffffffp4},
{0x1.acafffffffffep12, 0x1.2ffffffffffffp4},
{0x1.ffffffffffffep-958, 0x1.fffffffffffffp-320},
{0x1.ffffffffffffep-955, 0x1.fffffffffffffp-319},
{0x1.ffffffffffffep-952, 0x1.fffffffffffffp-318},
{0x1.ffffffffffffep-949, 0x1.fffffffffffffp-317},
{0x1.ffffffffffffep-946, 0x1.fffffffffffffp-316},
{0x1.ffffffffffffep-943, 0x1.fffffffffffffp-315},
{0x1.ffffffffffffep-940, 0x1.fffffffffffffp-314},
{0x1.ffffffffffffep-937, 0x1.fffffffffffffp-313},
{0x1.ffffffffffffep-934, 0x1.fffffffffffffp-312},
{0x1.ffffffffffffep-931, 0x1.fffffffffffffp-311},
{0x1.ffffffffffffep-1018, 0x1.fffffffffffffp-340},
{0x1.ffffffffffffep-928, 0x1.fffffffffffffp-310},
{0x1.ffffffffffffep-925, 0x1.fffffffffffffp-309},
{0x1.ffffffffffffep-922, 0x1.fffffffffffffp-308},
{0x1.ffffffffffffep-919, 0x1.fffffffffffffp-307},
{0x1.ffffffffffffep-916, 0x1.fffffffffffffp-306},
{0x1.ffffffffffffep-913, 0x1.fffffffffffffp-305},
{0x1.ffffffffffffep-910, 0x1.fffffffffffffp-304},
{0x1.ffffffffffffep-907, 0x1.fffffffffffffp-303},
{0x1.ffffffffffffep-904, 0x1.fffffffffffffp-302},
{0x0.0000000000007p-1022, 0x1.e9b5dba58189ep-358},
{0x1.ffffffffffffep-901, 0x1.fffffffffffffp-301},
{0x1.ffffffffffffep-898, 0x1.fffffffffffffp-300},
{0x0.0000000007ffp-1022, 0x1.ffeaa9c70ca31p-354},
{0x0.0000000007ffep-1022, 0x1.fffd5551c7149p-354},
{0x0.0000007fffffdp-1022, 0x1.ffffffcp-350},
{0x0.0000007fffffep-1022, 0x1.ffffffd555555p-350},
{0x0.0007ffffffffap-1022, 0x1.fffffffff8p-346},
{0x0.7ffffffffffffp-1022, 0x1.fffffffffffffp-342},
{0x1.ffffffffffffep-895, 0x1.fffffffffffffp-299},
{0x1.ffffffffffffep-892, 0x1.fffffffffffffp-298},
{0x1.ffffffffffffep-889, 0x1.fffffffffffffp-297},
{0x1.ffffffffffffep-886, 0x1.fffffffffffffp-296},
{0x1.ffffffffffffep-883, 0x1.fffffffffffffp-295},
{0x1.ffffffffffffep-1015, 0x1.fffffffffffffp-339},
{0x1.ffffffffffffep-880, 0x1.fffffffffffffp-294},
{0x1.ffffffffffffep-877, 0x1.fffffffffffffp-293},
{0x1.ffffffffffffep-874, 0x1.fffffffffffffp-292},
{0x1.ffffffffffffep-871, 0x1.fffffffffffffp-291},
{0x1.ffffffffffffep-868, 0x1.fffffffffffffp-290},
{0x1.ffffffffffffep-865, 0x1.fffffffffffffp-289},
{0x1.ffffffffffffep-862, 0x1.fffffffffffffp-288},
{0x1.ffffffffffffep-859, 0x1.fffffffffffffp-287},
{0x1.ffffffffffffep-856, 0x1.fffffffffffffp-286},
{0x1.ffffffffffffep-853, 0x1.fffffffffffffp-285},
{0x1.ffffffffffffep-850, 0x1.fffffffffffffp-284},
{0x1.ffffffffffffep-847, 0x1.fffffffffffffp-283},
{0x1.ffffffffffffep-844, 0x1.fffffffffffffp-282},
{0x1.ffffffffffffep-841, 0x1.fffffffffffffp-281},
{0x1.ffffffffffffep-838, 0x1.fffffffffffffp-280},
{0x1.ffffffffffffep-835, 0x1.fffffffffffffp-279},
{0x1.ffffffffffffep-1012, 0x1.fffffffffffffp-338},
{0x1.ffffffffffffep-832, 0x1.fffffffffffffp-278},
{0x1.ffffffffffffep-829, 0x1.fffffffffffffp-277},
{0x1.ffffffffffffep-826, 0x1.fffffffffffffp-276},
{0x1.ffffffffffffep-823, 0x1.fffffffffffffp-275},
{0x1.ffffffffffffep-820, 0x1.fffffffffffffp-274},
{0x1.ffffffffffffep-817, 0x1.fffffffffffffp-273},
{0x1.ffffffffffffep-814, 0x1.fffffffffffffp-272},
{0x1.ffffffffffffep-811, 0x1.fffffffffffffp-271},
{0x1.ffffffffffffep-808, 0x1.fffffffffffffp-270},
{0x1.ffffffffffffep-805, 0x1.fffffffffffffp-269},
{0x1.ffffffffffffep-802, 0x1.fffffffffffffp-268},
{0x1.ffffffffffffep-799, 0x1.fffffffffffffp-267},
{0x1.ffffffffffffep-796, 0x1.fffffffffffffp-266},
{0x1.ffffffffffffep-793, 0x1.fffffffffffffp-265},
{0x1.ffffffffffffep-790, 0x1.fffffffffffffp-264},
{0x1.ffffffffffffep-787, 0x1.fffffffffffffp-263},
{0x1.ffffffffffffep-1009, 0x1.fffffffffffffp-337},
{0x1.ffffffffffffep-784, 0x1.fffffffffffffp-262},
{0x1.ffffffffffffep-781, 0x1.fffffffffffffp-261},
{0x1.ffffffffffffep-778, 0x1.fffffffffffffp-260},
{0x1.ffffffffffffep-775, 0x1.fffffffffffffp-259},
{0x1.ffffffffffffep-772, 0x1.fffffffffffffp-258},
{0x1.ffffffffffffep-769, 0x1.fffffffffffffp-257},
{0x0.0000000000ffep-1022, 0x1.ffeaa9c70ca31p-355},
{0x0.0000000000fffp-1022, 0x1.fff5551c6fcd6p-355},
{0x0.0000000ffff86p-1022, 0x1.ffffaeaa9dbf1p-351},
{0x0.0000000ffffffp-1022, 0x1.ffffff5555552p-351},
{0x0.0000ffffffap-1022, 0x1.ffffffcp-347},
{0x0.0000ffffffff8p-1022, 0x1.ffffffffaaaabp-347},
{0x0.0fffffffffffbp-1022, 0x1.fffffffffffcbp-343}
};
for(double[] testCase: testCases)
failures+=testCubeRootCase(testCase[0], testCase[1]);
return failures;
}
public static void main(String [] argv) {
int failures = 0;
failures += testCubeRoot();
if (failures > 0) {
System.err.println("Testing the cube root incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851638
* @summary Tests for StrictMath.expm1
* @author Joseph D. Darcy
*/
/**
* The tests in ../Math/Expm1Tests.java test properties that should
* hold for any expm1 implementation, including the FDLIBM-based one
* required for StrictMath.expm1. Therefore, the test cases in
* ../Math/Expm1Tests.java are run against both the Math and
* StrictMath versions of expm1. The role of this test is to verify
* that the FDLIBM expm1 algorithm is being used by running golden
* file tests on values that may vary from one conforming expm1
* implementation to another.
*/
public class Expm1Tests {
private Expm1Tests(){}
static int testExpm1Case(double input, double expected) {
return Tests.test("StrictMath.expm1(double)", input,
StrictMath.expm1(input), expected);
}
static int testExpm1() {
int failures = 0;
// Test cases in the range [-36.75, 710]
double [][] testCases = {
{-0x1.580000008c619p3, -0x1.fffd3069586f6p-1},
{-0x1.380000008c721p3, -0x1.fff85bf4a6e98p-1},
{-0x1.180000008c9fap3, -0x1.ffeb3aeb95524p-1},
{-0x1.f0000001197ccp2, -0x1.ffc78aadc116ap-1},
{-0x1.b0000001197e7p2, -0x1.ff6687cca710bp-1},
{-0x1.70000001197f6p2, -0x1.fe5ed3992a519p-1},
{-0x1.30000001198p2, -0x1.fb9201482bdfap-1},
{-0x1.e000000233006p1, -0x1.f3f57b658d6fbp-1},
{-0x1.6000000233012p1, -0x1.df44d8ee30b76p-1},
{-0x1.c000000466028p0, -0x1.a7071a097ed5ep-1},
{-0x1.80000008cc052p-1, -0x1.0e25f8a4a95b7p-1},
{0x1.ffffffdccfeb7p-3, 0x1.22d78ef909144p-2},
{0x1.3ffffffb99fd7p0, 0x1.3ec38ed3629a6p1},
{0x1.1ffffffdccfebp1, 0x1.0f9b882a107edp3},
{0x1.9ffffffdccfebp1, 0x1.8ca53b70fa11bp4},
{0x1.0ffffffee67f6p2, 0x1.146bf132050c5p6},
{0x1.4ffffffee67f5p2, 0x1.7b21ede9f0bdap7},
{0x1.8ffffffee67f5p2, 0x1.0281a438aa523p9},
{0x1.cffffffee67f5p2, 0x1.5fc6b5cf322c4p10},
{0x1.07ffffff733fap3, 0x1.de5406b276b92p11},
{0x1.27ffffff733fap3, 0x1.451c8690d1567p13},
{0x1.47ffffff733fap3, 0x1.b9e62ae5924dfp14},
{0x1.67ffffff733fap3, 0x1.2c4eeb7089cp16},
{0x1.87ffffff733fap3, 0x1.982a24f2ab78ap17},
{0x1.a7ffffff733fap3, 0x1.1560a14319349p19},
{0x1.c7ffffff733fap3, 0x1.78fed772b40f2p20},
{0x1.e7ffffff733fap3, 0x1.0031f18ee602fp22},
{0x1.03ffffffb99fdp4, 0x1.5c348d8118f26p23},
{0x1.13ffffffb99fdp4, 0x1.d942943e22d74p24},
{0x1.23ffffffb99fcp4, 0x1.419d1309466ep26},
{0x1.33ffffffb99fcp4, 0x1.b51e403430afep27},
{0x1.43ffffffb99fcp4, 0x1.290d76c47bd4cp29},
{0x1.53ffffffb99fcp4, 0x1.93bc8061146dp30},
{0x1.63ffffffb99fbp4, 0x1.125e0665544a5p32},
{0x1.73ffffffb99fbp4, 0x1.74e75f9de5d7cp33},
{0x1.83ffffffb99fbp4, 0x1.fad42d3f28732p34},
{0x1.93ffffffb99fbp4, 0x1.586d071cb8f87p36},
{0x1.a3ffffffb99fbp4, 0x1.d41f91d0b4e6ep37},
{0x1.b3ffffffb99fbp4, 0x1.3e1f6e5bc0242p39},
{0x1.c3ffffffb99fbp4, 0x1.b05fa9aebfa64p40},
{0x1.d3ffffffb99fbp4, 0x1.25d410cc90a38p42},
{0x1.e3ffffffb99fbp4, 0x1.8f5aab33aa6c6p43},
{0x1.f3ffffffb99fbp4, 0x1.0f63a91bc9797p45},
{0x1.01ffffffdccfep5, 0x1.70db367c88b28p46},
{0x1.09ffffffdccfep5, 0x1.f553e36d2975fp47},
{0x1.11ffffffdccfep5, 0x1.54afff2230e99p49},
{0x1.19ffffffdccfep5, 0x1.cf0ad451f1e9fp50},
{0x1.21ffffffdccfep5, 0x1.3aab7c88ef991p52},
{0x1.29ffffffdccfep5, 0x1.abae41ecccd22p53},
{0x1.31ffffffdccfep5, 0x1.22a3a0462535fp55},
{0x1.39ffffffdccfdp5, 0x1.8b050329f95c8p56},
{0x1.41ffffffdccfdp5, 0x1.0c719224d80a2p58},
{0x1.49ffffffdccfdp5, 0x1.6cda4c755ea56p59},
{0x1.51ffffffdccfdp5, 0x1.efe2e2b6ad6ebp60},
{0x1.59ffffffdccfdp5, 0x1.50fd5a6337c61p62},
{0x1.61ffffffdccfdp5, 0x1.ca043518d78acp63},
{0x1.69ffffffdccfdp5, 0x1.374122dd2fbdbp65},
{0x1.71ffffffdccfdp5, 0x1.a709e46cc671ep66},
{0x1.79ffffffdccfdp5, 0x1.1f7c0c5482bf3p68},
{0x1.81ffffffdccfdp5, 0x1.86bb667297515p69},
{0x1.89ffffffdccfcp5, 0x1.0987aa8375abcp71},
{0x1.91ffffffdccfcp5, 0x1.68e48248f27ddp72},
{0x1.99ffffffdccfcp5, 0x1.ea8100a2e27e9p73},
{0x1.a1ffffffdccfcp5, 0x1.4d54fc02d9352p75},
{0x1.a9ffffffdccfcp5, 0x1.c50b8ceab6ad1p76},
{0x1.b1ffffffdccfcp5, 0x1.33e046afc7062p78},
{0x1.b9ffffffdccfcp5, 0x1.a2726cf2e78e3p79},
{0x1.c1ffffffdccfcp5, 0x1.1c5d3c581edf2p81},
{0x1.c9ffffffdccfcp5, 0x1.827db3961daecp82},
{0x1.d1ffffffdccfbp5, 0x1.06a5db797b4b2p84},
{0x1.d9ffffffdccfbp5, 0x1.64f9b90e23fb4p85},
{0x1.e1ffffffdccfbp5, 0x1.e52e132ebafe2p86},
{0x1.e9ffffffdccfbp5, 0x1.49b6c774442efp88},
{0x1.f1ffffffdccfbp5, 0x1.c020b4f9d926cp89},
{0x1.f9ffffffdccfbp5, 0x1.3088cda20d465p91},
{0x1.00ffffffee67ep6, 0x1.9de7b7a818186p92},
{0x1.04ffffffee67ep6, 0x1.194717f5da259p94},
{0x1.08ffffffee67ep6, 0x1.7e4bc97a2360dp95},
{0x1.0cffffffee67ep6, 0x1.03cc0e87f367bp97},
{0x1.10ffffffee67ep6, 0x1.6119d231b67f5p98},
{0x1.14ffffffee67ep6, 0x1.dfe9f0cbe5942p99},
{0x1.18ffffffee67ep6, 0x1.4622a079fc2a6p101},
{0x1.1cffffffee67ep6, 0x1.bb4386e45ae94p102},
{0x1.20ffffffee67ep6, 0x1.2d3a9d9e9fe6p104},
{0x1.24ffffffee67ep6, 0x1.9969a118d6261p105},
{0x1.28ffffffee67ep6, 0x1.1639871642331p107},
{0x1.2cffffffee67ep6, 0x1.7a2587603a84bp108},
{0x1.30ffffffee67ep6, 0x1.00fa2d6e6a76ep110},
{0x1.34ffffffee67ep6, 0x1.5d44af7562574p111},
{0x1.38ffffffee67ep6, 0x1.dab4705f88c02p112},
{0x1.3cffffffee67ep6, 0x1.42986b24fc9dcp114},
{0x1.40ffffffee67ep6, 0x1.b673dcb2fe519p115},
{0x1.44ffffffee67ep6, 0x1.29f59cd896383p117},
{0x1.48ffffffee67ep6, 0x1.94f806342143cp118},
{0x1.4cffffffee67ep6, 0x1.133471e4d5b38p120},
{0x1.50ffffffee67ep6, 0x1.760acce4f0e03p121},
{0x1.54ffffffee67ep6, 0x1.fc604454828ddp122},
{0x1.58ffffffee67ep6, 0x1.597a32eee8c46p124},
{0x1.5cffffffee67ep6, 0x1.d58d694102246p125},
{0x1.60ffffffee67ep6, 0x1.3f180bd3df0d2p127},
{0x1.64ffffffee67ep6, 0x1.b1b190d803f07p128},
{0x1.68ffffffee67ep6, 0x1.26b9b1cab82dap130},
{0x1.6cffffffee67ep6, 0x1.9092c44a68bc1p131},
{0x1.70ffffffee67ep6, 0x1.1037c0cf4a5a6p133},
{0x1.74ffffffee67ep6, 0x1.71fb79fed30fbp134},
{0x1.78ffffffee67ep6, 0x1.f6dbadec024eep135},
{0x1.7cffffffee67ep6, 0x1.55ba3f072a6dbp137},
{0x1.80ffffffee67ep6, 0x1.d074b338a9163p138},
{0x1.84ffffffee67ep6, 0x1.3ba167320351ap140},
{0x1.88ffffffee67ep6, 0x1.acfc7e2e0558bp141},
{0x1.8cffffffee67ep6, 0x1.2386c336b7163p143},
{0x1.90ffffffee67ep6, 0x1.8c39b90c7cdap144},
{0x1.94ffffffee67ep6, 0x1.0d435c84d4e66p146},
{0x1.98ffffffee67ep6, 0x1.6df76efd7275ep147},
{0x1.9cffffffee67ep6, 0x1.f1666c9163f86p148},
{0x1.a0ffffffee67ep6, 0x1.5204b679406b7p150},
{0x1.a4ffffffee67ep6, 0x1.cb6a267e94b7ap151},
{0x1.a8ffffffee67ep6, 0x1.38346236ba483p153},
{0x1.acffffffee67ep6, 0x1.a8547ff6d3311p154},
{0x1.b0ffffffee67ep6, 0x1.205cb8246899ap156},
{0x1.b4ffffffee67ep6, 0x1.87ecc28a831c1p157},
{0x1.b8ffffffee67ep6, 0x1.0a572df57323ep159},
{0x1.bcffffffee67ep6, 0x1.69fe8c886de24p160},
{0x1.c0ffffffee67ep6, 0x1.ec0055aa644acp161},
{0x1.c4ffffffee67ep6, 0x1.4e597c5197d13p163},
{0x1.c8ffffffee67ep6, 0x1.c66d9bb965746p164},
{0x1.ccffffffee67ep6, 0x1.34d0e22472ce2p166},
{0x1.d0ffffffee67ep6, 0x1.a3b971da5668ap167},
{0x1.d4ffffffee67ep6, 0x1.1d3b77e103d1ap169},
{0x1.d8ffffffee67ep6, 0x1.83abbf32ed4f6p170},
{0x1.dcffffffee67ep6, 0x1.07731e5137e95p172},
{0x1.e0ffffffee67ep6, 0x1.6610b39e7ce7p173},
{0x1.e4ffffffee67ep6, 0x1.e6a93f132076cp174},
{0x1.e8ffffffee67ep6, 0x1.4ab873ed0fb2cp176},
{0x1.ecffffffee67ep6, 0x1.c17eebfd11debp177},
{0x1.f0ffffffee67ep6, 0x1.3176cc87e9082p179},
{0x1.f4ffffffee67ep6, 0x1.9f2b2fe57487ap180},
{0x1.f8ffffffee67ep6, 0x1.1a22e9fe60816p182},
{0x1.fcffffffee67ep6, 0x1.7f768dd1738aap183},
{0x1.007ffffff733fp7, 0x1.049717079907bp185},
{0x1.027ffffff733fp7, 0x1.622dc5947dd63p186},
{0x1.047ffffff733fp7, 0x1.e160ff1ccd30cp187},
{0x1.067ffffff733fp7, 0x1.472180f8199d7p189},
{0x1.087ffffff733fp7, 0x1.bc9df0c9b6e0fp190},
{0x1.0a7ffffff733fp7, 0x1.2e26073757ed6p192},
{0x1.0c7ffffff733fp7, 0x1.9aa99688f714bp193},
{0x1.0e7ffffff733fp7, 0x1.1712f6523864dp195},
{0x1.107ffffff733fp7, 0x1.7b4d0d8e11012p196},
{0x1.127ffffff733fp7, 0x1.01c301c6bf29cp198},
{0x1.147ffffff733fp7, 0x1.5e55a41486608p199},
{0x1.167ffffff733fp7, 0x1.dc276c8c7156p200},
{0x1.187ffffff733fp7, 0x1.4394876ddc7dap202},
{0x1.1a7ffffff733fp7, 0x1.b7ca840a6b3bap203},
{0x1.1c7ffffff733fp7, 0x1.2ade7851ad0fep205},
{0x1.1e7ffffff733fp7, 0x1.963482987606p206},
{0x1.207ffffff733fp7, 0x1.140b84f56a91bp208},
{0x1.227ffffff733fp7, 0x1.772f1dec03a66p209},
{0x1.247ffffff733fp7, 0x1.fded90f5af3ap210},
{0x1.267ffffff733fp7, 0x1.5a88311cf6cbdp212},
{0x1.287ffffff733fp7, 0x1.d6fc5e99a419dp213},
{0x1.2a7ffffff733fp7, 0x1.40116b9759ebap215},
{0x1.2c7ffffff733fp7, 0x1.b304801416466p216},
{0x1.2e7ffffff733fp7, 0x1.27a0063dbe9cep218},
{0x1.307ffffff733fp7, 0x1.91cbd14945353p219},
{0x1.327ffffff733fp7, 0x1.110c7e4340e4fp221},
{0x1.347ffffff733fp7, 0x1.731c9ec8ce996p222},
{0x1.367ffffff733fp7, 0x1.f864aa9acffbdp223},
{0x1.387ffffff733fp7, 0x1.56c54eff8fbcdp225},
{0x1.3a7ffffff733fp7, 0x1.d1dfaced4eb1p226},
{0x1.3c7ffffff733fp7, 0x1.3c98120a95d78p228},
{0x1.3e7ffffff733fp7, 0x1.ae4bbfa449eaap229},
{0x1.407ffffff733fp7, 0x1.246a97a9838dcp231},
{0x1.427ffffff733fp7, 0x1.8d6f603164cebp232},
{0x1.447ffffff733fp7, 0x1.0e15cad8b775ep234},
{0x1.467ffffff733fp7, 0x1.6f15705b3f514p235},
{0x1.487ffffff733fp7, 0x1.f2eb25494787dp236},
{0x1.4a7ffffff733fp7, 0x1.530ce0608a8acp238},
{0x1.4c7ffffff733fp7, 0x1.ccd12fa07172p239},
{0x1.4e7ffffff733fp7, 0x1.39285fa9c08e7p241},
{0x1.507ffffff733fp7, 0x1.a9a01de01fd02p242},
{0x1.527ffffff733fp7, 0x1.213e13894e05p244},
{0x1.547ffffff733fp7, 0x1.891f0d4674b33p245},
{0x1.567ffffff733fp7, 0x1.0b275393c60b2p247},
{0x1.587ffffff733fp7, 0x1.6b1973327581dp248},
{0x1.5a7ffffff733fp7, 0x1.ed80d645874cfp249},
{0x1.5c7ffffff733fp7, 0x1.4f5ec835b4172p251},
{0x1.5e7ffffff733fp7, 0x1.c7d0bf3aec5fcp252},
{0x1.607ffffff733fp7, 0x1.35c239a263125p254},
{0x1.627ffffff733fp7, 0x1.a501765319bp255},
{0x1.647ffffff733fp7, 0x1.1e1a611707cfbp257},
{0x1.667ffffff733fp7, 0x1.84dab6dcaac3cp258},
{0x1.687ffffff733fp7, 0x1.08410192ab89ep260},
{0x1.6a7ffffff733fp7, 0x1.67288834edb2fp261},
{0x1.6c7ffffff733fp7, 0x1.e825934abdad9p262},
{0x1.6e7ffffff733fp7, 0x1.4bbae9c58a222p264},
{0x1.707ffffff733fp7, 0x1.c2de34b24b161p265},
{0x1.727ffffff733fp7, 0x1.3265856c8dbdcp267},
{0x1.747ffffff733fp7, 0x1.a06fa4ee04c8ep268},
{0x1.767ffffff733fp7, 0x1.1aff67d171068p270},
{0x1.787ffffff733fp7, 0x1.80a23ba5cc0fep271},
{0x1.7a7ffffff733fp7, 0x1.0562be333b5b6p273},
{0x1.7c7ffffff733fp7, 0x1.6342909f8e806p274},
{0x1.7e7ffffff733fp7, 0x1.e2d932898c11cp275},
{0x1.807ffffff733ep7, 0x1.482128a65b0aap277},
{0x1.827ffffff733ep7, 0x1.bdf9696894p278},
{0x1.847ffffff733ep7, 0x1.2f1228ca0924p280},
{0x1.867ffffff733ep7, 0x1.9bea8605e05b8p281},
{0x1.887ffffff733ep7, 0x1.17ed0f7b60befp283},
{0x1.8a7ffffff733ep7, 0x1.7c757ab028d2cp284},
{0x1.8c7ffffff733ep7, 0x1.028c73122cbaap286},
{0x1.8e7ffffff733ep7, 0x1.5f676e04b872p287},
{0x1.907ffffff733ep7, 0x1.dd9b8aa6c07f4p288},
{0x1.927ffffff733ep7, 0x1.449168bd6830bp290},
{0x1.947ffffff733ep7, 0x1.b922372b1b22fp291},
{0x1.967ffffff733ep7, 0x1.2bc809c589606p293},
{0x1.987ffffff733ep7, 0x1.9771f652c776ap294},
{0x1.9a7ffffff733ep7, 0x1.14e3401b07fc7p296},
{0x1.9c7ffffff733ep7, 0x1.785453659b7d4p297},
{0x1.9e7ffffff733ep7, 0x1.ff7c1414d829fp298},
{0x1.a07ffffff733ep7, 0x1.5b97024b58a63p300},
{0x1.a27ffffff733ep7, 0x1.d86c72ba13072p301},
{0x1.a47ffffff733ep7, 0x1.410b8e3e0a59p303},
{0x1.a67ffffff733ep7, 0x1.b458783157a34p304},
{0x1.a87ffffff733ep7, 0x1.28870eb1e33efp306},
{0x1.aa7ffffff733ep7, 0x1.9305d2eedd47p307},
{0x1.ac7ffffff733ep7, 0x1.11e1e1f93656cp309},
{0x1.ae7ffffff733ep7, 0x1.743ea58a8a142p310},
{0x1.b07ffffff733ep7, 0x1.f9eeda68dbff6p311},
{0x1.b27ffffff733ep7, 0x1.57d12fadfda18p313},
{0x1.b47ffffff733ep7, 0x1.d34bc24ce61e7p314},
{0x1.b67ffffff733ep7, 0x1.3d8f7da8d8d95p316},
{0x1.b87ffffff733ep7, 0x1.af9c071bbd116p317},
{0x1.ba7ffffff733ep7, 0x1.254f1e2943f7fp319},
{0x1.bc7ffffff733ep7, 0x1.8ea5f9553ce5ep320},
{0x1.be7ffffff733ep7, 0x1.0ee8dda0a100cp322},
{0x1.c07ffffff733ep7, 0x1.7034513ceac7dp323},
{0x1.c27ffffff733ep7, 0x1.f4710dcb08bdcp324},
{0x1.c47ffffff733ep7, 0x1.5415d8b9ef19cp326},
{0x1.c67ffffff733ep7, 0x1.ce3951590b045p327},
{0x1.c87ffffff733ep7, 0x1.3a1d1bcad2ec4p329},
{0x1.ca7ffffff733ep7, 0x1.aaecbef297a4ap330},
{0x1.cc7ffffff733ep7, 0x1.22201f0c6ae88p332},
{0x1.ce7ffffff733ep7, 0x1.8a524760ebdc1p333},
{0x1.d07ffffff733ep7, 0x1.0bf81bdd2ba52p335},
{0x1.d27ffffff733ep7, 0x1.6c3536f34b0c2p336},
{0x1.d47ffffff733ep7, 0x1.ef02835e6a7d8p337},
{0x1.d67ffffff733ep7, 0x1.5064e04e480fep339},
{0x1.d87ffffff733ep7, 0x1.c934f847894a8p340},
{0x1.da7ffffff733ep7, 0x1.36b44dbc8b633p342},
{0x1.dc7ffffff733ep7, 0x1.a64a7b24ebae2p343},
{0x1.de7ffffff733ep7, 0x1.1ef9f881e57b8p345},
{0x1.e07ffffff733ep7, 0x1.860a9b4bcf9dfp346},
{0x1.e27ffffff733ep7, 0x1.090f85bb33493p348},
{0x1.e47ffffff733ep7, 0x1.6841377bd96e9p349},
{0x1.e67ffffff733ep7, 0x1.e9a310bd2715dp350},
{0x1.e87ffffff733ep7, 0x1.4cbe299b1372dp352},
{0x1.ea7ffffff733ep7, 0x1.c43e8fef69d0dp353},
{0x1.ec7ffffff733ep7, 0x1.3354f8e156a72p355},
{0x1.ee7ffffff733ep7, 0x1.a1b51787582dfp356},
{0x1.f07ffffff733ep7, 0x1.1bdc91f54d333p358},
{0x1.f27ffffff733ep7, 0x1.81ced3ada5ec9p359},
{0x1.f47ffffff733ep7, 0x1.062f0486db268p361},
{0x1.f67ffffff733ep7, 0x1.645833fb72196p362},
{0x1.f87ffffff733ep7, 0x1.e4528bf7332d2p363},
{0x1.fa7ffffff733ep7, 0x1.492198206b3aep365},
{0x1.fc7ffffff733ep7, 0x1.bf55f194851b5p366},
{0x1.fe7ffffff733ep7, 0x1.2fff02e67affep368},
{0x1.003ffffffb99fp8, 0x1.9d2c7052fc80ep369},
{0x1.013ffffffb99fp8, 0x1.18c7d31687cep371},
{0x1.023ffffffb99fp8, 0x1.7d9ecf7b00132p372},
{0x1.033ffffffb99fp8, 0x1.035681cb5b766p374},
{0x1.043ffffffb99fp8, 0x1.607a0decadfaep375},
{0x1.053ffffffb99fp8, 0x1.df10cb910ae14p376},
{0x1.063ffffffb99fp8, 0x1.458f0fad99f57p378},
{0x1.073ffffffb99fp8, 0x1.ba7af6e654fa2p379},
{0x1.083ffffffb99fp8, 0x1.2cb251c2631d6p381},
{0x1.093ffffffb99fp8, 0x1.98b06224611f2p382},
{0x1.0a3ffffffb99fp8, 0x1.15bba3d909807p384},
{0x1.0b3ffffffb99fp8, 0x1.797a6e0440f8fp385},
{0x1.0c3ffffffb99fp8, 0x1.0085e752522ap387},
{0x1.0d3ffffffb99fp8, 0x1.5ca6a71ef489ep388},
{0x1.0e3ffffffb99fp8, 0x1.d9dda6826dfc7p389},
{0x1.0f3ffffffb99fp8, 0x1.420674603ebb2p391},
{0x1.103ffffffb99fp8, 0x1.b5ad79fec979p392},
{0x1.113ffffffb99fp8, 0x1.296ecbb3d2db7p394},
{0x1.123ffffffb99fp8, 0x1.9440c9fa6362ap395},
{0x1.133ffffffb99fp8, 0x1.12b7ec73193e4p397},
{0x1.143ffffffb99fp8, 0x1.75618ef49dffep398},
{0x1.153ffffffb99fp8, 0x1.fb7a3e462b12ap399},
{0x1.163ffffffb99fp8, 0x1.58dde1b590206p401},
{0x1.173ffffffb99fp8, 0x1.d4b8f4351faecp402},
{0x1.183ffffffb99fp8, 0x1.3e87aaa373892p404},
{0x1.193ffffffb99fp8, 0x1.b0ed5561210d9p405},
{0x1.1a3ffffffb99fp8, 0x1.263457411e3a5p407},
{0x1.1b3ffffffb99fp8, 0x1.8fdd8535244cdp408},
{0x1.1c3ffffffb99fp8, 0x1.0fbc955d170d1p410},
{0x1.1d3ffffffb99fp8, 0x1.7154125122a86p411},
{0x1.1e3ffffffb99fp8, 0x1.f5f8270411675p412},
{0x1.1f3ffffffb99fp8, 0x1.551fa026c4e4cp414},
{0x1.203ffffffb99fp8, 0x1.cfa28c83a9c15p415},
{0x1.213ffffffb99fp8, 0x1.3b12972ef5f7ap417},
{0x1.223ffffffb99fp8, 0x1.ac3a63f8c3fc9p418},
{0x1.233ffffffb99fp8, 0x1.2302db376285dp420},
{0x1.243ffffffb99fp8, 0x1.8b867194fa443p421},
{0x1.253ffffffb99fp8, 0x1.0cc98750c45aep423},
{0x1.263ffffffb99fp8, 0x1.6d51d877b6f1bp424},
{0x1.273ffffffb99fp8, 0x1.f0855ddfe3faap425},
{0x1.283ffffffb99fp8, 0x1.516bc53aea3aap427},
{0x1.293ffffffb99fp8, 0x1.ca9a47b823396p428},
{0x1.2a3ffffffb99fp8, 0x1.37a71f0652462p430},
{0x1.2b3ffffffb99fp8, 0x1.a794811822eb3p431},
{0x1.2c3ffffffb99fp8, 0x1.1fda3ea9c1a4fp433},
{0x1.2d3ffffffb99fp8, 0x1.873b6d3965cp434},
{0x1.2e3ffffffb99fp8, 0x1.09deab488e539p436},
{0x1.2f3ffffffb99fp8, 0x1.695ac21e2870ep437},
{0x1.303ffffffb99fp8, 0x1.eb21b852a647cp438},
{0x1.313ffffffb99fp8, 0x1.4dc2340b86b4cp440},
{0x1.323ffffffb99fp8, 0x1.c59ffe8afa62cp441},
{0x1.333ffffffb99fp8, 0x1.3445277810b78p443},
{0x1.343ffffffb99fp8, 0x1.a2fb88779894fp444},
{0x1.353ffffffb99fp8, 0x1.1cba68f09f8c5p446},
{0x1.363ffffffb99fp8, 0x1.82fc56a008db6p447},
{0x1.373ffffffb99fp8, 0x1.06fbea7eda2dfp449},
{0x1.383ffffffb99fp8, 0x1.656eb0513614ep450},
{0x1.393ffffffb99fp8, 0x1.e5cd0c4b86aaap451},
{0x1.3a3ffffffb99fp8, 0x1.4a22d0026e7ffp453},
{0x1.3b3ffffffb99fp8, 0x1.c0b38a21c236cp454},
{0x1.3c3ffffffb99fp8, 0x1.30ec961ce5379p456},
{0x1.3d3ffffffb99fp8, 0x1.9e6f56344e9dp457},
{0x1.3e3ffffffb99fp8, 0x1.19a341a8e1ccbp459},
{0x1.3f3ffffffb99fp8, 0x1.7ec90ca3a1c6dp460},
{0x1.403ffffffb99fp8, 0x1.04212e6d536d6p462},
{0x1.413ffffffb99fp8, 0x1.618d84739e91cp463},
{0x1.423ffffffb99fp8, 0x1.e087302e9607ap464},
{0x1.433ffffffb99fp8, 0x1.468d7cd8e4417p466},
{0x1.443ffffffb99fp8, 0x1.bbd4c40e0317cp467},
{0x1.453ffffffb99fp8, 0x1.2d9d50d6e1436p469},
{0x1.463ffffffb99fp8, 0x1.99efc6cf25729p470},
{0x1.473ffffffb99fp8, 0x1.1694b0b33138ap472},
{0x1.483ffffffb99fp8, 0x1.7aa16e7b0810dp473},
{0x1.493ffffffb99fp8, 0x1.014e60cc3c10bp475},
{0x1.4a3ffffffb99fp8, 0x1.5db7203d316b3p476},
{0x1.4b3ffffffb99fp8, 0x1.db4ffad383047p477},
{0x1.4c3ffffffb99fp8, 0x1.43021e96bc60ep479},
{0x1.4d3ffffffb99fp8, 0x1.b703864c0ed74p480},
{0x1.4e3ffffffb99fp8, 0x1.2a573dd0a80e6p482},
{0x1.4f3ffffffb99fp8, 0x1.957cb72b9f3f6p483},
{0x1.503ffffffb99fp8, 0x1.138e9e333d9afp485},
{0x1.513ffffffb99fp8, 0x1.76855bb82cbcep486},
{0x1.523ffffffb99fp8, 0x1.fd06d7237d52bp487},
{0x1.533ffffffb99fp8, 0x1.59eb65b9e296ap489},
{0x1.543ffffffb99fp8, 0x1.d627438458c6ap490},
{0x1.553ffffffb99fp8, 0x1.3f80999182b7ap492},
{0x1.563ffffffb99fp8, 0x1.b23fab41d7fcdp493},
{0x1.573ffffffb99fp8, 0x1.271a437ca4dd9p495},
{0x1.583ffffffb99fp8, 0x1.9116048ecdd82p496},
{0x1.593ffffffb99fp8, 0x1.1090f28f03784p498},
{0x1.5a3ffffffb99fp8, 0x1.7274b4471d222p499},
{0x1.5b3ffffffb99fp8, 0x1.f78071e284acfp500},
{0x1.5c3ffffffb99fp8, 0x1.562a3748e0ae8p502},
{0x1.5d3ffffffb99fp8, 0x1.d10ce1fc412f2p503},
{0x1.5e3ffffffb99fp8, 0x1.3c08d26ba29edp505},
{0x1.5f3ffffffb99fp8, 0x1.ad890dbdcc46ap506},
{0x1.603ffffffb99fp8, 0x1.23e648944393ap508},
{0x1.613ffffffb99fp8, 0x1.8cbb8c9e43a63p509},
{0x1.623ffffffb99fp8, 0x1.0d9b966e13d61p511},
{0x1.633ffffffb99fp8, 0x1.6e6f586d0888dp512},
{0x1.643ffffffb99fp8, 0x1.f20966b5813aep513},
{0x1.653ffffffb99fp8, 0x1.5273779badaf2p515},
{0x1.663ffffffb99fp8, 0x1.cc00ae664a89p516},
{0x1.673ffffffb99fp8, 0x1.389aae1391554p518},
{0x1.683ffffffb99fp8, 0x1.a8df88f5b2588p519},
{0x1.693ffffffb99fp8, 0x1.20bb34172b66ap521},
{0x1.6a3ffffffb99fp8, 0x1.886d2d5f07833p522},
{0x1.6b3ffffffb99fp8, 0x1.0aae72b8de01ep524},
{0x1.6c3ffffffb99fp8, 0x1.6a7528c7487fep525},
{0x1.6d3ffffffb99fp8, 0x1.eca18af43a36cp526},
{0x1.6e3ffffffb99fp8, 0x1.4ec709b53a35fp528},
{0x1.6f3ffffffb99fp8, 0x1.c702815c30a11p529},
{0x1.703ffffffb99fp8, 0x1.353611c2fab72p531},
{0x1.713ffffffb99fp8, 0x1.a442f8858a925p532},
{0x1.723ffffffb99fp8, 0x1.1d98ed4a7bba3p534},
{0x1.733ffffffb99fp8, 0x1.842ac5348b7cep535},
{0x1.743ffffffb99fp8, 0x1.07c97097fb529p537},
{0x1.753ffffffb99fp8, 0x1.6686064a6be2ap538},
{0x1.763ffffffb99fp8, 0x1.e748b46cfe14cp539},
{0x1.773ffffffb99fp8, 0x1.4b24d0e9033c7p541},
{0x1.783ffffffb99fp8, 0x1.c21233e5293dap542},
{0x1.793ffffffb99fp8, 0x1.31dae2fdf0407p544},
{0x1.7a3ffffffb99fp8, 0x1.9fb3386e7303dp545},
{0x1.7b3ffffffb99fp8, 0x1.1a7f5bb80b183p547},
{0x1.7c3ffffffb99fp8, 0x1.7ff432dfa67a9p548},
{0x1.7d3ffffffb99fp8, 0x1.04ec79737cde7p550},
{0x1.7e3ffffffb99fp8, 0x1.62a1d2414486ep551},
{0x1.7f3ffffffb99fp8, 0x1.e1feb963592a3p552},
{0x1.803ffffffb99fp8, 0x1.478cb0da3248p554},
{0x1.813ffffffb99fp8, 0x1.bd2f9f74b3ecep555},
{0x1.823ffffffb99fp8, 0x1.2e8907921a545p557},
{0x1.833ffffffb99fp8, 0x1.9b3025158e763p558},
{0x1.843ffffffb99fp8, 0x1.176e672da841p560},
{0x1.853ffffffb99fp8, 0x1.7bc9557d90bb5p561},
{0x1.863ffffffb99fp8, 0x1.021776f23b20ap563},
{0x1.873ffffffb99fp8, 0x1.5ec86e4bf78ccp564},
{0x1.883ffffffb99fp8, 0x1.dcc3708ecfe88p565},
{0x1.893ffffffb99fp8, 0x1.43fe8d7ac0079p567},
{0x1.8a3ffffffb99fp8, 0x1.b85a9de96d206p568},
{0x1.8b3ffffffb99fp8, 0x1.2b406595ebc2fp570},
{0x1.8c3ffffffb99fp8, 0x1.96b99b42ee81ep571},
{0x1.8d3ffffffb99fp8, 0x1.1465f7bc5d4f3p573},
{0x1.8e3ffffffb99fp8, 0x1.77aa0c86e3254p574},
{0x1.8f3ffffffb99fp8, 0x1.fe94a5f24f127p575},
{0x1.903ffffffb99fp8, 0x1.5af9bc5f10484p577},
{0x1.913ffffffb99fp8, 0x1.d796b1199ca0dp578},
{0x1.923ffffffb99fp8, 0x1.407a4b0a99581p580},
{0x1.933ffffffb99fp8, 0x1.b393098be48c6p581},
{0x1.943ffffffb99fp8, 0x1.2800e367d7873p583},
{0x1.953ffffffb99fp8, 0x1.924f782080a9p584},
{0x1.963ffffffb99fp8, 0x1.1165f5b7b4e77p586},
{0x1.973ffffffb99fp8, 0x1.739637ce995dep587},
{0x1.983ffffffb99fp8, 0x1.f909ef553fe1dp588},
{0x1.993ffffffb99fp8, 0x1.57359ec295bd8p590},
{0x1.9a3ffffffb99fp8, 0x1.d278529f70c72p591},
{0x1.9b3ffffffb99fp8, 0x1.3cffce16c6a9fp593},
{0x1.9c3ffffffb99fp8, 0x1.aed8bd0d76c2ep594},
{0x1.9d3ffffffb99fp8, 0x1.24ca67ad88b68p596},
{0x1.9e3ffffffb99fp8, 0x1.8df19938fe6d4p597},
{0x1.9f3ffffffb99fp8, 0x1.0e6e49b5016fbp599},
{0x1.a03ffffffb99fp8, 0x1.6f8db78116a48p600},
{0x1.a13ffffffb99fp8, 0x1.f38e9ecb87da4p601},
{0x1.a23ffffffb99fp8, 0x1.537bf81122a93p603},
{0x1.a33ffffffb99fp8, 0x1.cd682d2c39ab4p604},
{0x1.a43ffffffb99fp8, 0x1.398efb7895c02p606},
{0x1.a53ffffffb99fp8, 0x1.aa2b938729ffap607},
{0x1.a63ffffffb99fp8, 0x1.219cd9531c9cep609},
{0x1.a73ffffffb99fp8, 0x1.899fdc76e059bp610},
{0x1.a83ffffffb99fp8, 0x1.0b7edc8aa647ep612},
{0x1.a93ffffffb99fp8, 0x1.6b906c232d65ep613},
{0x1.aa3ffffffb99fp8, 0x1.ee22898b97fbep614},
{0x1.ab3ffffffb99fp8, 0x1.4fccab37000cep616},
{0x1.ac3ffffffb99fp8, 0x1.c866193ae89dbp617},
{0x1.ad3ffffffb99fp8, 0x1.3627b854c5c27p619},
{0x1.ae3ffffffb99fp8, 0x1.a58b68788e1e6p620},
{0x1.af3ffffffb99fp8, 0x1.1e781f8a5efe5p622},
{0x1.b03ffffffb99fp8, 0x1.855a202353f77p623},
{0x1.b13ffffffb99fp8, 0x1.0897974f62fe1p625},
{0x1.b23ffffffb99fp8, 0x1.679e369129826p626},
{0x1.b33ffffffb99fp8, 0x1.e8c58542c521dp627},
{0x1.b43ffffffb99fp8, 0x1.4c279b7142392p629},
{0x1.b53ffffffb99fp8, 0x1.c371efb43e76ep630},
{0x1.b63ffffffb99fp8, 0x1.32c9ea1ab59ccp632},
{0x1.b73ffffffb99fp8, 0x1.a0f817c69fb0ap633},
{0x1.b83ffffffb99fp8, 0x1.1b5c21ca08788p635},
{0x1.b93ffffffb99fp8, 0x1.812042e534a64p636},
{0x1.ba3ffffffb99fp8, 0x1.05b86359a079cp638},
{0x1.bb3ffffffb99fp8, 0x1.63b6f7fddd3efp639},
{0x1.bc3ffffffb99fp8, 0x1.e3776813fda8ep640},
{0x1.bd3ffffffb99fp8, 0x1.488cac4ce84e7p642},
{0x1.be3ffffffb99fp8, 0x1.be8b89ed9a77dp643},
{0x1.bf3ffffffb99fp8, 0x1.2f75768394a5p645},
{0x1.c03ffffffb99fp8, 0x1.9c717dbaae2b8p646},
{0x1.c13ffffffb99fp8, 0x1.1848c7ccfefe3p648},
{0x1.c23ffffffb99fp8, 0x1.7cf223c0074fbp649},
{0x1.c33ffffffb99fp8, 0x1.02e12a3ec0173p651},
{0x1.c43ffffffb99fp8, 0x1.5fda91f1b0d98p652},
{0x1.c53ffffffb99fp8, 0x1.de38089682abp653},
{0x1.c63ffffffb99fp8, 0x1.44fbc1a5fe2ddp655},
{0x1.c73ffffffb99fp8, 0x1.b9b2c1a7cc7aap656},
{0x1.c83ffffffb99fp8, 0x1.2c2a43919580dp658},
{0x1.c93ffffffb99fp8, 0x1.97f7770145248p659},
{0x1.ca3ffffffb99fp8, 0x1.153df9919867p661},
{0x1.cb3ffffffb99fp8, 0x1.78cfa212f8edcp662},
{0x1.cc3ffffffb99fp8, 0x1.0011d5d26caedp664},
{0x1.cd3ffffffb99fp8, 0x1.5c08e649b4b94p665},
{0x1.ce3ffffffb99fp8, 0x1.d9073dd4a4c7bp666},
{0x1.cf3ffffffb99fp8, 0x1.4174bfa6c0d24p668},
{0x1.d03ffffffb99fp8, 0x1.b4e7710dea691p669},
{0x1.d13ffffffb99fp8, 0x1.28e8378f2345ap671},
{0x1.d23ffffffb99fp8, 0x1.9389e0a91894fp672},
{0x1.d33ffffffb99fp8, 0x1.123b9f58df0dap674},
{0x1.d43ffffffb99fp8, 0x1.74b89d97dfdd3p675},
{0x1.d53ffffffb99fp8, 0x1.fa94a04bdb05cp676},
{0x1.d63ffffffb99fp8, 0x1.5841d736b633cp678},
{0x1.d73ffffffb99fp8, 0x1.d3e4df4a846ddp679},
{0x1.d83ffffffb99fp8, 0x1.3df78ac6c50cep681},
{0x1.d93ffffffb99fp8, 0x1.b02972b428f19p682},
{0x1.da3ffffffb99fp8, 0x1.25af390e18cbep684},
{0x1.db3ffffffb99fp8, 0x1.8f289821f41b9p685},
{0x1.dc3ffffffb99fp8, 0x1.0f41a1a5d8764p687},
{0x1.dd3ffffffb99fp8, 0x1.70acf6623ff32p688},
{0x1.de3ffffffb99fp8, 0x1.f515070ef61acp689},
{0x1.df3ffffffb99fp8, 0x1.5485473c56dfcp691},
{0x1.e03ffffffb99fp8, 0x1.ced0c4e4d59e4p692},
{0x1.e13ffffffb99fp8, 0x1.3a8407ca209c6p694},
{0x1.e23ffffffb99fp8, 0x1.ab78a196b76fdp695},
{0x1.e33ffffffb99fp8, 0x1.227f2ee6fa305p697},
{0x1.e43ffffffb99fp8, 0x1.8ad37b3bad33ep698},
{0x1.e53ffffffb99fp8, 0x1.0c4fe93ccdf88p700},
{0x1.e63ffffffb99fp8, 0x1.6cac8cde514efp701},
{0x1.e73ffffffb99fp8, 0x1.efa4b5032b54fp702},
{0x1.e83ffffffb99fp8, 0x1.50d31930266e8p704},
{0x1.e93ffffffb99fp8, 0x1.c9cac6ffa71cbp705},
{0x1.ea3ffffffb99fp8, 0x1.371a1bc09599dp707},
{0x1.eb3ffffffb99fp8, 0x1.a6d4d9189f018p708},
{0x1.ec3ffffffb99fp8, 0x1.1f580038307ccp710},
{0x1.ed3ffffffb99fp8, 0x1.868a6825185b7p711},
{0x1.ee3ffffffb99fp8, 0x1.09665f229766bp713},
{0x1.ef3ffffffb99fp8, 0x1.68b741d009e02p714},
{0x1.f03ffffffb99fp8, 0x1.ea437fb4bc319p715},
{0x1.f13ffffffb99fp8, 0x1.4d2b3038bf046p717},
{0x1.f23ffffffb99ep8, 0x1.c4d2be652cea4p718},
{0x1.f33ffffffb99ep8, 0x1.33b9ac04c0212p720},
{0x1.f43ffffffb99ep8, 0x1.a23df502a4a3ap721},
{0x1.f53ffffffb99ep8, 0x1.1c39946547606p723},
{0x1.f63ffffffb99ep8, 0x1.824d3d6b0103dp724},
{0x1.f73ffffffb99ep8, 0x1.0684ec9be79c4p726},
{0x1.f83ffffffb99ep8, 0x1.64ccf65229834p727},
{0x1.f93ffffffb99ep8, 0x1.e4f13d25df78ap728},
{0x1.fa3ffffffb99ep8, 0x1.498d6fcce3f5ep730},
{0x1.fb3ffffffb99ep8, 0x1.bfe8844c8ea89p731},
{0x1.fc3ffffffb99ep8, 0x1.30629e3b46a18p733},
{0x1.fd3ffffffb99ep8, 0x1.9db3d1822eed1p734},
{0x1.fe3ffffffb99ep8, 0x1.1923d3162d5cep736},
{0x1.ff3ffffffb99ep8, 0x1.7e1bd9f724dbcp737},
{0x1.001ffffffdccfp9, 0x1.03ab7b2c9b517p739},
{0x1.009ffffffdccfp9, 0x1.60ed8bd54933ep740},
{0x1.011ffffffdccfp9, 0x1.dfadc3cd79f32p741},
{0x1.019ffffffdccfp9, 0x1.45f9bbb2a35d1p743},
{0x1.021ffffffdccfp9, 0x1.bb0bf258b833ap744},
{0x1.029ffffffdccfp9, 0x1.2d14d8520baf7p746},
{0x1.031ffffffdccfp9, 0x1.99364b282dd34p747},
{0x1.039ffffffdccfp9, 0x1.1616a4367556fp749},
{0x1.041ffffffdccfp9, 0x1.79f61d0f30fbp750},
{0x1.049ffffffdccfp9, 0x1.00d9f49709365p752},
{0x1.051ffffffdccfp9, 0x1.5d18e41eebfc4p753},
{0x1.059ffffffdccfp9, 0x1.da78ea95d97f9p754},
{0x1.061ffffffdccfp9, 0x1.426ff7fe794b6p756},
{0x1.069ffffffdccfp9, 0x1.b63ce2972ea1ep757},
{0x1.071ffffffdccfp9, 0x1.29d0407f62d33p759},
{0x1.079ffffffdccfp9, 0x1.94c53ee806803p760},
{0x1.081ffffffdccfp9, 0x1.1311eff49ae9ap762},
{0x1.089ffffffdccfp9, 0x1.75dbe653c2ceap763},
{0x1.091ffffffdccfp9, 0x1.fc2085b6a9375p764},
{0x1.099ffffffdccfp9, 0x1.594ee148935c8p766},
{0x1.0a1ffffffdccfp9, 0x1.d55288db74dc3p767},
{0x1.0a9ffffffdccfp9, 0x1.3ef00912762eap769},
{0x1.0b1ffffffdccfp9, 0x1.b17b2f7ee7f4ep770},
{0x1.0b9ffffffdccfp9, 0x1.2694bd41472c4p772},
{0x1.0c1ffffffdccfp9, 0x1.90608a1681a3ep773},
{0x1.0c9ffffffdccfp9, 0x1.10159ec1486a4p775},
{0x1.0d1ffffffdccfp9, 0x1.71cd15bf6b516p776},
{0x1.0d9ffffffdccfp9, 0x1.f69ca06d83551p777},
{0x1.0e1ffffffdccfp9, 0x1.558f65bed5d1ap779},
{0x1.0e9ffffffdccfp9, 0x1.d03a766bae541p780},
{0x1.0f1ffffffdccfp9, 0x1.3b79d39d672c6p782},
{0x1.0f9ffffffdccfp9, 0x1.acc6b3ef261e7p783},
{0x1.101ffffffdccfp9, 0x1.2362355c94574p785},
{0x1.109ffffffdccfp9, 0x1.8c080a68bcd97p786},
{0x1.111ffffffdccfp9, 0x1.0d21994e9f02ap788},
{0x1.119ffffffdccfp9, 0x1.6dc98ba5b51bp789},
{0x1.121ffffffdccfp9, 0x1.f1280e4617147p790},
{0x1.129ffffffdccfp9, 0x1.51da544077fa2p792},
{0x1.131ffffffdccfp9, 0x1.cb308b8399fb7p793},
{0x1.139ffffffdccfp9, 0x1.380d3c9a00e7ep795},
{0x1.141ffffffdccfp9, 0x1.a81f4b2e55334p796},
{0x1.149ffffffdccfp9, 0x1.20388fdc417d5p798},
{0x1.151ffffffdccfp9, 0x1.87bb9df31efbp799},
{0x1.159ffffffdccfp9, 0x1.0a35c88f80cbp801},
{0x1.161ffffffdccfp9, 0x1.69d128b22d25ap802},
{0x1.169ffffffdccfp9, 0x1.ebc2a4ab78bb5p803},
{0x1.171ffffffdccfp9, 0x1.4e2f8fdd883d6p805},
{0x1.179ffffffdccfp9, 0x1.c634a0cec7546p806},
{0x1.181ffffffdccfp9, 0x1.34aa294e0c99ep808},
{0x1.189ffffffdccfp9, 0x1.a384d0e8ecc3p809},
{0x1.191ffffffdccfp9, 0x1.1d17b4109e865p811},
{0x1.199ffffffdccfp9, 0x1.837b23284f5e9p812},
{0x1.1a1ffffffdccfp9, 0x1.075215b6dcdc8p814},
{0x1.1a9ffffffdccfp9, 0x1.65e3cde76e421p815},
{0x1.1b1ffffffdccfp9, 0x1.e66c397f0e285p816},
{0x1.1b9ffffffdccfp9, 0x1.4a8efbf67ceccp818},
{0x1.1c1ffffffdccfp9, 0x1.c1468f660e51bp819},
{0x1.1c9ffffffdccfp9, 0x1.31507f4997713p821},
{0x1.1d1ffffffdccfp9, 0x1.9ef72130544cep822},
{0x1.1d9ffffffdccfp9, 0x1.19ff898e9368dp824},
{0x1.1e1ffffffdccfp9, 0x1.7f4678d82ff18p825},
{0x1.1e9ffffffdccfp9, 0x1.04766a36fd582p827},
{0x1.1f1ffffffdccfp9, 0x1.62015c9e2f34p828},
{0x1.1f9ffffffdccfp9, 0x1.e124a317460fp829},
{0x1.201ffffffdccfp9, 0x1.46f87c3b54d8ep831},
{0x1.209ffffffdccfp9, 0x1.bc6630ce5faecp832},
{0x1.211ffffffdccfp9, 0x1.2e00246624382p834},
{0x1.219ffffffdccfp9, 0x1.9a761879cac82p835},
{0x1.221ffffffdccfp9, 0x1.16eff82ee1911p837},
{0x1.229ffffffdccfp9, 0x1.7b1d7e2eda2c6p838},
{0x1.231ffffffdccfp9, 0x1.01a2afc0d75c2p840},
{0x1.239ffffffdccfp9, 0x1.5e29b684536ep841},
{0x1.241ffffffdccfp9, 0x1.dbebb83e52c5dp842},
{0x1.249ffffffdccfp9, 0x1.436bf4aaba53p844},
{0x1.251ffffffdccfp9, 0x1.b7935ef798935p845},
{0x1.259ffffffdccfp9, 0x1.2ab8fec5df362p847},
{0x1.261ffffffdccfp9, 0x1.9601939d5137dp848},
{0x1.269ffffffdccfp9, 0x1.13e8e80d6759dp850},
{0x1.271ffffffdccfp9, 0x1.770012b39ed67p851},
{0x1.279ffffffdccfp9, 0x1.fdada086b9c52p852},
{0x1.281ffffffdccfp9, 0x1.5a5cbd9bfe665p854},
{0x1.289ffffffdccfp9, 0x1.d6c15030e89c1p855},
{0x1.291ffffffdccfp9, 0x1.3fe9499128953p857},
{0x1.299ffffffdccfp9, 0x1.b2cdf43b59797p858},
{0x1.2a1ffffffdccfp9, 0x1.277af4d2d449ap860},
{0x1.2a9ffffffdccfp9, 0x1.91996fd498417p861},
{0x1.2b1ffffffdccfp9, 0x1.10ea41886590dp863},
{0x1.2b9ffffffdccfp9, 0x1.72ee16480890ep864},
{0x1.2c1ffffffdccfp9, 0x1.f8256bd5a1072p865},
{0x1.2c9ffffffdccfp9, 0x1.569a543aa97d8p867},
{0x1.2d1ffffffdccfp9, 0x1.d1a5429cffadp868},
{0x1.2d9ffffffdccfp9, 0x1.3c705f8813894p870},
{0x1.2e1ffffffdccfp9, 0x1.ae15cb5be04dap871},
{0x1.2e9ffffffdccfp9, 0x1.2445ed3e27324p873},
{0x1.2f1ffffffdccfp9, 0x1.8d3d8ab9f0bdep874},
{0x1.2f9ffffffdccfp9, 0x1.0df3ed3fc701dp876},
{0x1.301ffffffdccfp9, 0x1.6ee76926e122bp877},
{0x1.309ffffffdccfp9, 0x1.f2ac9640362cap878},
{0x1.311ffffffdccfp9, 0x1.52e25d083c6f6p880},
{0x1.319ffffffdccfp9, 0x1.cc9767a099276p881},
{0x1.321ffffffdccfp9, 0x1.39011b7511e91p883},
{0x1.329ffffffdccfp9, 0x1.a96abf82e5bedp884},
{0x1.331ffffffdccfp9, 0x1.2119ceff4e062p886},
{0x1.339ffffffdccfp9, 0x1.88edc2473f3cfp887},
{0x1.341ffffffdccfp9, 0x1.0b05d4146a019p889},
{0x1.349ffffffdccfp9, 0x1.6aebebe3397ccp890},
{0x1.351ffffffdccfp9, 0x1.ed42f5104656ep891},
{0x1.359ffffffdccfp9, 0x1.4f34bafe2847bp893},
{0x1.361ffffffdccfp9, 0x1.c79797c887ff8p894},
{0x1.369ffffffdccfp9, 0x1.359b628909b0ap896},
{0x1.371ffffffdccfp9, 0x1.a4ccac407db6ep897},
{0x1.379ffffffdccfp9, 0x1.1df681534dcc2p899},
{0x1.381ffffffdccfp9, 0x1.84a9f4d4f272ap900},
{0x1.389ffffffdccfp9, 0x1.081fdf276bf44p902},
{0x1.391ffffffdccfp9, 0x1.66fb7f67746f6p903},
{0x1.399ffffffdccfp9, 0x1.e7e85e064cb73p904},
{0x1.3a1ffffffdccfp9, 0x1.4b91516684d28p906},
{0x1.3a9ffffffdccfp9, 0x1.c2a5ac0f3d022p907},
{0x1.3b1ffffffdccfp9, 0x1.323f1a3f5edc4p909},
{0x1.3b9ffffffdccfp9, 0x1.a03b6d89faf11p910},
{0x1.3c1ffffffdccfp9, 0x1.1adbebbbf9351p912},
{0x1.3c9ffffffdccfp9, 0x1.80720118fc863p913},
{0x1.3d1ffffffdccfp9, 0x1.0541f7d976c95p915},
{0x1.3d9ffffffdccfp9, 0x1.631604f454091p916},
{0x1.3e1ffffffdccfp9, 0x1.e29ca75828ca4p917},
{0x1.3e9ffffffdccfp9, 0x1.47f803db3082ep919},
{0x1.3f1ffffffdccfp9, 0x1.bdc17ddb963f2p920},
{0x1.3f9ffffffdccfp9, 0x1.2eec285d246c2p922},
{0x1.401ffffffdccfp9, 0x1.9bb6dfb8d5a7bp923},
{0x1.409ffffffdccfp9, 0x1.17c9f5ff316ddp925},
{0x1.411ffffffdccfp9, 0x1.7c45c625cf3bcp926},
{0x1.419ffffffdccfp9, 0x1.026c07ca1067p928},
{0x1.421ffffffdccfp9, 0x1.5f3b5e200997dp929},
{0x1.429ffffffdccfp9, 0x1.dd5fa7afd8289p930},
{0x1.431ffffffdccfp9, 0x1.4468b644f2c7fp932},
{0x1.439ffffffdccfp9, 0x1.b8eae6ffb1c26p933},
{0x1.441ffffffdccfp9, 0x1.2ba272f04fa72p935},
{0x1.449ffffffdccfp9, 0x1.973edf89954efp936},
{0x1.451ffffffdccfp9, 0x1.14c088262904bp938},
{0x1.459ffffffdccfp9, 0x1.782523695aef2p939},
{0x1.461ffffffdccfp9, 0x1.ff3bf1add8023p940},
{0x1.469ffffffdccfp9, 0x1.5b6b6cd54844dp942},
{0x1.471ffffffdccfp9, 0x1.d831362a33e02p943},
{0x1.479ffffffdccfp9, 0x1.40e34cdaa0c9dp945},
{0x1.481ffffffdccfp9, 0x1.b421c1b7c391cp946},
{0x1.489ffffffdccfp9, 0x1.2861e04eed965p948},
{0x1.491ffffffdccfp9, 0x1.92d34a1abd55p949},
{0x1.499ffffffdccfp9, 0x1.11bf8a7ca8dc9p951},
{0x1.4a1ffffffdccfp9, 0x1.740ff8ac10594p952},
{0x1.4a9ffffffdccfp9, 0x1.f9af6a367aa8cp953},
{0x1.4b1ffffffdccfp9, 0x1.57a613525a444p955},
{0x1.4b9ffffffdccfp9, 0x1.d3112a55b14f7p956},
{0x1.4c1ffffffdccfp9, 0x1.3d67ac204487bp958},
{0x1.4c9ffffffdccfp9, 0x1.af65e8a8eee76p959},
{0x1.4d1ffffffdccfp9, 0x1.252a57165ab35p961},
{0x1.4d9ffffffdccfp9, 0x1.8e73fcebbcdf2p962},
{0x1.4e1ffffffdccfp9, 0x1.0ec6e5905727p964},
{0x1.4e9ffffffdccfp9, 0x1.7006260fe518p965},
{0x1.4f1ffffffdccfp9, 0x1.f4324dde1b853p966},
{0x1.4f9ffffffdccfp9, 0x1.53eb342838912p968},
{0x1.501ffffffdccfp9, 0x1.cdff5c312677p969},
{0x1.509ffffffdccfp9, 0x1.39f5b8e646512p971},
{0x1.511ffffffdccfp9, 0x1.aab736e0229e8p972},
{0x1.519ffffffdccfp9, 0x1.21fbbe2a7cc33p974},
{0x1.521ffffffdccfp9, 0x1.8a20d5dbe17b1p975},
{0x1.529ffffffdccfp9, 0x1.0bd6823000616p977},
{0x1.531ffffffdccfp9, 0x1.6c078c0f5af0cp978},
{0x1.539ffffffdccfp9, 0x1.eec471cd26923p979},
{0x1.541ffffffdccfp9, 0x1.503ab239a52eep981},
{0x1.549ffffffdccfp9, 0x1.c8fba42a91b8p982},
{0x1.551ffffffdccfp9, 0x1.368d584898928p984},
{0x1.559ffffffdccfp9, 0x1.a61587d0f8cb4p985},
{0x1.561ffffffdccfp9, 0x1.1ed5fcb4fed8p987},
{0x1.569ffffffdccfp9, 0x1.85d9b3294cbccp988},
{0x1.571ffffffdccfp9, 0x1.08ee496ae24e1p990},
{0x1.579ffffffdccfp9, 0x1.68140b7c89c5cp991},
{0x1.581ffffffdccfp9, 0x1.e965aba3129a2p992},
{0x1.589ffffffdccfp9, 0x1.4c9470ba47e91p994},
{0x1.591ffffffdccfp9, 0x1.c405db1de4f69p995},
{0x1.599ffffffdccfp9, 0x1.332e6fade5fp997},
{0x1.5a1ffffffdccfp9, 0x1.a180b7549973p998},
{0x1.5a9ffffffdccfp9, 0x1.1bb8fa248f731p1000},
{0x1.5b1ffffffdccfp9, 0x1.819e736fecc0ap1001},
{0x1.5b9ffffffdccfp9, 0x1.060e248ff8e45p1003},
{0x1.5c1ffffffdccfp9, 0x1.642b85802c37dp1004},
{0x1.5c9ffffffdccfp9, 0x1.e415d17516714p1005},
{0x1.5d1ffffffdccfp9, 0x1.48f8532dcd8aap1007},
{0x1.5d9ffffffdccfp9, 0x1.bf1dda53d4168p1008},
{0x1.5e1ffffffdccfp9, 0x1.2fd8e4c6c1a74p1010},
{0x1.5e9ffffffdccfp9, 0x1.9cf8a1a8a05e1p1011},
{0x1.5f1ffffffdccfp9, 0x1.18a49e2c20c14p1013},
{0x1.5f9ffffffdccfp9, 0x1.7d6ef5a877896p1014},
{0x1.601ffffffdccfp9, 0x1.0335fd2d4d32ap1016},
{0x1.609ffffffdccfp9, 0x1.604ddb98aeeb6p1017},
{0x1.611ffffffdccfp9, 0x1.ded4b9cce1c65p1018},
{0x1.619ffffffdccep9, 0x1.45663d67095d1p1020},
{0x1.621ffffffdccep9, 0x1.ba437b80a6915p1021},
{0x1.629ffffffdccep9, 0x1.2c8c9d8cda0c8p1023},
};
for (double[] testCase: testCases)
failures+=testExpm1Case(testCase[0], testCase[1]);
return failures;
}
public static void main(String [] argv) {
int failures = 0;
failures += testExpm1();
if (failures > 0) {
System.err.println("Testing expm1 incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851625
* @summary Tests for StrictMath.{sinh, cosh, tanh}
* @author Joseph D. Darcy
*/
/**
* The tests in ../Math/HyperbolicTests.java test properties that
* should hold for any implementation of the hyperbolic functions
* sinh, cos, and tanh, including the FDLIBM-based ones required by
* the StrictMath class. Therefore, the test cases in
* ../Math/HyperbolicTests.java are run against both the Math and
* StrictMath versions of the hyperbolic methods. The role of this
* test is to verify that the FDLIBM algorithms are being used by
* running golden file tests on values that may vary from one
* conforming implementation of the hyperbolics to another.
*/
public class HyperbolicTests {
private HyperbolicTests(){}
static int testSinhCase(double input, double expected) {
return Tests.test("StrictMath.sinh(double)", input,
StrictMath.sinh(input), expected);
}
static int testCoshCase(double input, double expected) {
return Tests.test("StrictMath.cosh(double)", input,
StrictMath.cosh(input), expected);
}
static int testTanhCase(double input, double expected) {
return Tests.test("StrictMath.tanh(double)", input,
StrictMath.tanh(input), expected);
}
static int testSinh() {
int failures = 0;
double [][] testCases = {
{0x1.5798ee2308c3ap-27, 0x1.5798ee2308c3bp-27},
{0x1.ffffffffffff8p-26, 0x1.ffffffffffffap-26},
{0x1.ffffffffffffep-26, 0x1.0p-25},
{0x1.ffffffffffff8p-25, 0x1.ffffffffffffep-25},
{0x1.ffffffffffffap-25, 0x1.0p-24},
{0x1.ad7f29abcaf47p-24, 0x1.ad7f29abcaf53p-24},
{0x1.ad7f29abcaf48p-24, 0x1.ad7f29abcaf54p-24},
{0x1.fffffffffffeap-24, 0x1.0p-23},
{0x1.ffffffffffff8p-24, 0x1.0000000000007p-23},
{0x1.fffffffffffaap-23, 0x1.0p-22},
{0x1.ffffffffffff8p-23, 0x1.0000000000027p-22},
{0x1.ffffffffffeaap-22, 0x1.0p-21},
{0x1.ffffffffffff8p-22, 0x1.00000000000a7p-21},
{0x1.ffffffffffaaap-21, 0x1.0p-20},
{0x1.ffffffffffff8p-21, 0x1.00000000002a7p-20},
{0x1.0c6f7a0b5ed8cp-20, 0x1.0c6f7a0b5f09fp-20},
{0x1.0c6f7a0b5ed8dp-20, 0x1.0c6f7a0b5f0ap-20},
{0x1.fffffffffeaaap-20, 0x1.0p-19},
{0x1.ffffffffffff8p-20, 0x1.0000000000aa7p-19},
{0x1.ffffffffffff8p-19, 0x1.0000000002aa7p-18},
{0x1.ffffffffffff7p-18, 0x1.000000000aaa6p-17},
{0x1.4f8b588e368d9p-17, 0x1.4f8b588e4e928p-17},
{0x1.ffffffffffffep-17, 0x1.000000002aaa9p-16},
{0x1.0p-16, 0x1.000000002aaaap-16},
{0x1.fffffffffffffp-16, 0x1.00000000aaaabp-15},
{0x1.fffffffffeaaap-15, 0x1.00000002aap-14},
{0x1.ffffffffffffep-15, 0x1.00000002aaaa9p-14},
{0x1.0p-14, 0x1.00000002aaaaap-14},
{0x1.a36e2eb1c3dd4p-14, 0x1.a36e2ebd7e43ap-14},
{0x1.a36e2eb1c3f8cp-14, 0x1.a36e2ebd7e5f1p-14},
{0x1.a36e2eb1c432cp-14, 0x1.a36e2ebd7e991p-14},
{0x1.fffffffffffffp-14, 0x1.0000000aaaaabp-13},
{0x1.ffffffffffffep-13, 0x1.0000002aaaaa9p-12},
{0x1.0p-12, 0x1.0000002aaaaaap-12},
{0x1.ffffffffff7f9p-12, 0x1.000000aaaa6a9p-11},
{0x1.fffffffffffffp-12, 0x1.000000aaaaaadp-11},
{0x1.ffffffffffffep-11, 0x1.000002aaaaacbp-10},
{0x1.0p-10, 0x1.000002aaaaaccp-10},
{0x1.0624dd2f1a79p-10, 0x1.0624e00c1c776p-10},
{0x1.0624dd2f1a8c9p-10, 0x1.0624e00c1c8bp-10},
{0x1.0624dd2f1a9fcp-10, 0x1.0624e00c1c9e3p-10},
{0x1.ffffffffffffep-10, 0x1.00000aaaaaccbp-9},
{0x1.0p-9, 0x1.00000aaaaacccp-9},
{0x1.ffffffffffe4ap-9, 0x1.00002aaaacbf2p-8},
{0x1.fffffffffffffp-9, 0x1.00002aaaacccdp-8},
{0x1.fffffffffff9dp-8, 0x1.0000aaaaccc9bp-7},
{0x1.ffffffffffffep-8, 0x1.0000aaaacccccp-7},
{0x1.0p-7, 0x1.0000aaaaccccdp-7},
{0x1.47ae147ae146fp-7, 0x1.47af7a654e9e2p-7},
{0x1.47ae147ae147ap-7, 0x1.47af7a654e9eep-7},
{0x1.47ae147ae147bp-7, 0x1.47af7a654e9efp-7},
{0x1.fffffffffffb6p-7, 0x1.0002aaaccccb4p-6},
{0x1.fffffffffffcap-7, 0x1.0002aaaccccbep-6},
{0x1.ffffffffffff7p-7, 0x1.0002aaaccccd5p-6},
{0x1.fffffffffffe9p-6, 0x1.000aaacccd001p-5},
{0x1.ffffffffffff7p-6, 0x1.000aaacccd008p-5},
{0x1.fffffffffffffp-6, 0x1.000aaacccd00dp-5},
{0x1.ffffffffffff6p-5, 0x1.002aacccd9cd7p-4},
{0x1.ffffffffffff8p-5, 0x1.002aacccd9cd9p-4},
{0x1.0p-4, 0x1.002aacccd9cddp-4},
{0x1.9999999999995p-4, 0x1.9a487337b59afp-4},
{0x1.9999999999996p-4, 0x1.9a487337b59afp-4},
{0x1.9999999999998p-4, 0x1.9a487337b59b1p-4},
{0x1.ffffffffffffap-4, 0x1.00aaccd00d2edp-3},
{0x1.ffffffffffffcp-4, 0x1.00aaccd00d2efp-3},
{0x1.ffffffffffff3p-3, 0x1.02accd9d080fbp-2},
{0x1.ffffffffffffdp-3, 0x1.02accd9d08101p-2},
{0x1.fffffffffffffp-3, 0x1.02accd9d08101p-2},
{0x1.fffffffffffecp-2, 0x1.0acd00fe63b8cp-1},
{0x1.ffffffffffffcp-2, 0x1.0acd00fe63b94p-1},
{0x1.0p-1, 0x1.0acd00fe63b97p-1},
{0x1.ffffffffffff6p-1, 0x1.2cd9fc44eb97ap0},
{0x1.ffffffffffffep-1, 0x1.2cd9fc44eb981p0},
{0x1.fffffffffffffp0, 0x1.d03cf63b6e19ep1},
{0x1.0p1, 0x1.d03cf63b6e1ap1},
{0x1.fffffffffffffp1, 0x1.b4a380370362dp4},
{0x1.0p2, 0x1.b4a380370363p4},
{0x1.ffffffffffffcp2, 0x1.749ea514eca4ep10},
{0x1.0p3, 0x1.749ea514eca66p10},
{0x1.fffffffffffffp3, 0x1.0f2ebd0a7ffdcp22},
{0x1.0p4, 0x1.0f2ebd0a7ffe4p22},
{0x1.fffffffffff68p4, 0x1.1f43fcc4b5b83p45},
{0x1.fffffffffffd4p4, 0x1.1f43fcc4b6316p45},
{0x1.0p5, 0x1.1f43fcc4b662cp45},
};
for (double[] testCase: testCases)
failures+=testSinhCase(testCase[0], testCase[1]);
return failures;
}
static int testCosh() {
int failures = 0;
double [][] testCases = {
{0x1.fffffffffb49fp-8, 0x1.00020000aaaabp0},
{0x1.47ae147ae0e45p-7, 0x1.000346de27853p0},
{0x1.fffffffffd9f3p-7, 0x1.0008000aaab05p0},
{0x1.ffffffffff9f1p-7, 0x1.0008000aaab05p0},
{0x1.fffffffffe27dp-6, 0x1.002000aaac169p0},
{0x1.ffffffffff27bp-6, 0x1.002000aaac16bp0},
{0x1.ffffffffffb9cp-5, 0x1.00800aab05b1ep0},
{0x1.ffffffffffd9dp-5, 0x1.00800aab05b1fp0},
{0x1.9999999999368p-4, 0x1.0147f40224b2ep0},
{0x1.9999999999727p-4, 0x1.0147f40224b35p0},
{0x1.ffffffffffed1p-4, 0x1.0200aac16db6cp0},
{0x1.fffffffffffd1p-4, 0x1.0200aac16db6ep0},
{0x1.ffffffffffeb4p-3, 0x1.080ab05ca613bp0},
{0x1.ffffffffffff2p-3, 0x1.080ab05ca6146p0},
{0x1.ffffffffffff3p-2, 0x1.20ac1862ae8cep0},
{0x1.ffffffffffff9p-2, 0x1.20ac1862ae8dp0},
{0x1.0p0, 0x1.8b07551d9f551p0},
{0x1.ffffffffffffbp0, 0x1.e18fa0df2d9b3p1},
{0x1.ffffffffffffep0, 0x1.e18fa0df2d9b8p1},
{0x1.fffffffffffffp0, 0x1.e18fa0df2d9bap1},
{0x1.ffffffffffff9p1, 0x1.b4ee858de3e68p4},
{0x1.ffffffffffffep1, 0x1.b4ee858de3e7ap4},
{0x1.fffffffffffffp1, 0x1.b4ee858de3e7dp4},
{0x1.ffffffffffffcp2, 0x1.749eaa93f4e5ep10},
{0x1.ffffffffffffdp2, 0x1.749eaa93f4e64p10},
{0x1.0p3, 0x1.749eaa93f4e76p10},
{0x1.fffffffffff6fp3, 0x1.0f2ebd0a7fb9p22},
{0x1.0p4, 0x1.0f2ebd0a8005cp22},
{0x1.fffffffffffd4p4, 0x1.1f43fcc4b6316p45},
{0x1.0p5, 0x1.1f43fcc4b662cp45},
};
for (double[] testCase: testCases)
failures+=testCoshCase(testCase[0], testCase[1]);
return failures;
}
static int testTanh() {
int failures = 0;
double [][] testCases = {
{0x1.5798ee2308c36p-27, 0x1.5798ee2308c36p-27},
{0x1.ffffffffffffep-26, 0x1.ffffffffffffbp-26},
{0x1.ffffffffffffep-25, 0x1.ffffffffffff3p-25},
{0x1.ad7f29abcaf47p-24, 0x1.ad7f29abcaf2dp-24},
{0x1.ad7f29abcaf48p-24, 0x1.ad7f29abcaf2ep-24},
{0x1.ffffffffffffep-24, 0x1.fffffffffffd3p-24},
{0x1.ffffffffffffep-23, 0x1.fffffffffff53p-23},
{0x1.ffffffffffffep-22, 0x1.ffffffffffd53p-22},
{0x1.ffffffffffffep-21, 0x1.ffffffffff553p-21},
{0x1.0c6f7a0b5ed8dp-20, 0x1.0c6f7a0b5e767p-20},
{0x1.ffffffffffffep-20, 0x1.fffffffffd553p-20},
{0x1.ffffffffffffep-19, 0x1.fffffffff5553p-19},
{0x1.fffffffffffffp-18, 0x1.ffffffffd5555p-18},
{0x1.0p-17, 0x1.ffffffffd5556p-18},
{0x1.4f8b588e368edp-17, 0x1.4f8b588e0685p-17},
{0x1.fffffffffffffp-17, 0x1.ffffffff55554p-17},
{0x1.fffffffffffffp-16, 0x1.fffffffd55555p-16},
{0x1.0p-15, 0x1.fffffffd55556p-16},
{0x1.fffffffffe5ddp-15, 0x1.fffffff553b33p-15},
{0x1.fffffffffffffp-15, 0x1.fffffff555554p-15},
{0x1.a36e2eb1c432dp-14, 0x1.a36e2e9a4f663p-14},
{0x1.ffffffffffffep-14, 0x1.ffffffd555553p-14},
{0x1.0p-13, 0x1.ffffffd555555p-14},
{0x1.ffffffffffd51p-13, 0x1.ffffff55552aap-13},
{0x1.fffffffffffffp-13, 0x1.ffffff5555559p-13},
{0x1.ffffffffffffep-12, 0x1.fffffd5555597p-12},
{0x1.0p-11, 0x1.fffffd5555599p-12},
{0x1.fffffffffff1p-11, 0x1.fffff555558a9p-11},
{0x1.0p-10, 0x1.fffff5555599ap-11},
{0x1.0624dd2f1a9c6p-10, 0x1.0624d77516cabp-10},
{0x1.0624dd2f1a9f8p-10, 0x1.0624d77516cdep-10},
{0x1.fffffffffffddp-10, 0x1.ffffd55559976p-10},
{0x1.fffffffffffffp-10, 0x1.ffffd55559999p-10},
{0x1.ffffffffffffcp-9, 0x1.ffff555599993p-9},
{0x1.ffffffffffffep-9, 0x1.ffff555599996p-9},
{0x1.ffffffffffff8p-8, 0x1.fffd555999924p-8},
{0x1.ffffffffffffep-8, 0x1.fffd555999929p-8},
{0x1.47ae147ae1458p-7, 0x1.47ab48ae4593cp-7},
{0x1.47ae147ae1464p-7, 0x1.47ab48ae45947p-7},
{0x1.ffffffffffffep-7, 0x1.fff5559997df6p-7},
{0x1.fffffffffffffp-7, 0x1.fff5559997df8p-7},
{0x1.ffffffffffff9p-6, 0x1.ffd559992b1d8p-6},
{0x1.ffffffffffffep-6, 0x1.ffd559992b1dcp-6},
{0x1.ffffffffffff9p-5, 0x1.ff55997e030d1p-5},
{0x1.fffffffffffffp-5, 0x1.ff55997e030d6p-5},
{0x1.9999999999996p-4, 0x1.983d7795f4137p-4},
{0x1.9999999999997p-4, 0x1.983d7795f4137p-4},
{0x1.fffffffffffffp-4, 0x1.fd5992bc4b834p-4},
{0x1.0p-3, 0x1.fd5992bc4b834p-4},
{0x1.fffffffffffffp-3, 0x1.f597ea69a1c86p-3},
{0x1.ffffffffffffcp-2, 0x1.d9353d7568aefp-2},
{0x1.ffffffffffffep-2, 0x1.d9353d7568af3p-2},
{0x1.ffffffffffffbp-1, 0x1.85efab514f393p-1},
{0x1.ffffffffffffep-1, 0x1.85efab514f393p-1},
{0x1.fffffffffffd3p0, 0x1.ed9505e1bc3cep-1},
{0x1.fffffffffffe1p0, 0x1.ed9505e1bc3cfp-1},
{0x1.ffffffffffed8p1, 0x1.ffa81708a0b4p-1},
{0x1.fffffffffff92p1, 0x1.ffa81708a0b41p-1},
};
for (double[] testCase: testCases)
failures+=testTanhCase(testCase[0], testCase[1]);
return failures;
}
public static void main(String [] argv) {
int failures = 0;
failures += testSinh();
failures += testCosh();
failures += testTanh();
if (failures > 0) {
System.err.println("Testing the hyperbolics incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851638
* @summary Tests for StrictMath.hypot
* @author Joseph D. Darcy
*/
/**
* The tests in ../Math/HypotTests.java test properties that should
* hold for any hypot implementation, including the FDLIBM-based one
* required for StrictMath.hypot. Therefore, the test cases in
* ../Math/HypotTests.java are run against both the Math and
* StrictMath versions of hypot. The role of this test is to verify
* that the FDLIBM hypot algorithm is being used by running golden
* file tests on values that may vary from one conforming hypot
* implementation to another.
*/
public class HypotTests {
private HypotTests(){}
static int testHypotCase(double input1, double input2, double expected) {
return Tests.test("StrictMath.hypot(double)", input1, input2,
StrictMath.hypot(input1, input2), expected);
}
static int testHypot() {
int failures = 0;
double [][] testCases = {
{0x1.0p0, 0x1.ffffffffffab5p-1, 0x1.6a09e667f39edp0},
{0x1.0p0, 0x1.ffffffffffffbp0, 0x1.1e3779b97f4a6p1},
{0x1.0p0, 0x1.7ffffffffffffp1, 0x1.94c583ada5b51p1},
{0x1.0p0, 0x1.ffffffffffffdp1, 0x1.07e0f66afed06p2},
{0x1.0p0, 0x1.3fffffffffffdp2, 0x1.465655f122ff3p2},
{0x1.0p0, 0x1.4p2, 0x1.465655f122ff6p2},
{0x1.0p0, 0x1.7ffffffffffffp2, 0x1.854bfb363dc38p2},
{0x1.0p0, 0x1.8p2, 0x1.854bfb363dc39p2},
{0x1.0p0, 0x1.bfffffffffffep2, 0x1.c48c6001f0abdp2},
{0x1.0p0, 0x1.fffffffffffffp2, 0x1.01fe03f61badp3},
{0x1.0p0, 0x1.1fffffffffffap3, 0x1.21c5b70d9f81dp3},
{0x1.0p0, 0x1.3ffffffffffe5p3, 0x1.419894c2329d5p3},
{0x1.0p0, 0x1.3ffffffffffe7p3, 0x1.419894c2329d8p3},
{0x1.0p0, 0x1.5ffffffffff7ep3, 0x1.617398f2aa9c6p3},
{0x1.0p0, 0x1.5ffffffffff8dp3, 0x1.617398f2aa9d5p3},
{0x1.0p0, 0x1.7ffffffffff9bp3, 0x1.8154be27734c1p3},
{0x1.0p0, 0x1.8p3, 0x1.8154be2773526p3},
{0x1.0p0, 0x1.9fffffffffff4p3, 0x1.a13a9cb996644p3},
{0x1.0p0, 0x1.9ffffffffffffp3, 0x1.a13a9cb99664fp3},
{0x1.0p0, 0x1.bfffffffffffep3, 0x1.c12432fec0327p3},
{0x1.0p0, 0x1.cp3, 0x1.c12432fec0329p3},
{0x1.0p0, 0x1.dffffffffffbcp3, 0x1.e110c39105f6bp3},
{0x1.0p0, 0x1.ep3, 0x1.e110c39105fafp3},
{0x1.0p0, 0x1.ffffffffffeafp3, 0x1.007fe00ff5fc8p4},
{0x1.0p0, 0x1.0fffffffffff4p4, 0x1.10785dd689a1cp4},
{0x1.0p0, 0x1.0fffffffffffbp4, 0x1.10785dd689a23p4},
{0x1.0p0, 0x1.1ffffffffff92p4, 0x1.2071b0abcd7cap4},
{0x1.0p0, 0x1.1ffffffffff99p4, 0x1.2071b0abcd7d1p4},
{0x1.0p0, 0x1.2fffffffffffcp4, 0x1.306bb705ae7bfp4},
{0x1.0p0, 0x1.2ffffffffffffp4, 0x1.306bb705ae7c3p4},
{0x1.0p0, 0x1.3fffffffffffdp4, 0x1.4066560954a8bp4},
{0x1.0p0, 0x1.4fffffffffe14p4, 0x1.506177f548fcfp4},
{0x1.0p0, 0x1.5p4, 0x1.506177f5491bbp4},
{0x1.0p0, 0x1.5fffffffffffdp4, 0x1.605d0af9d3a42p4},
{0x1.0p0, 0x1.5fffffffffffep4, 0x1.605d0af9d3a42p4},
{0x1.0p0, 0x1.6fffffffffff8p4, 0x1.7059005e2c015p4},
{0x1.0p0, 0x1.6ffffffffffffp4, 0x1.7059005e2c01dp4},
{0x1.0p0, 0x1.7fffffffffffdp4, 0x1.80554bdc2dc4dp4},
{0x1.0p0, 0x1.7ffffffffffffp4, 0x1.80554bdc2dc4ep4},
{0x1.0p0, 0x1.8fffffffffe68p4, 0x1.9051e3235a2cp4},
{0x1.0p0, 0x1.9p4, 0x1.9051e3235a458p4},
{0x1.0p0, 0x1.9fffffffffff4p4, 0x1.a04ebd789d00cp4},
{0x1.0p0, 0x1.ap4, 0x1.a04ebd789d019p4},
{0x1.0p0, 0x1.afffffffffed8p4, 0x1.b04bd36b639fbp4},
{0x1.0p0, 0x1.affffffffff43p4, 0x1.b04bd36b63a66p4},
{0x1.0p0, 0x1.bfffffffffe3ep4, 0x1.c0491e9ab90fdp4},
{0x1.0p0, 0x1.cp4, 0x1.c0491e9ab92bfp4},
{0x1.0p0, 0x1.cfffffffffed8p4, 0x1.d0469986884d6p4},
{0x1.0p0, 0x1.cfffffffffee8p4, 0x1.d0469986884e5p4},
{0x1.0p0, 0x1.dfffffffffe5cp4, 0x1.e0443f6a33104p4},
{0x1.0p0, 0x1.dffffffffffffp4, 0x1.e0443f6a332a7p4},
{0x1.0p0, 0x1.efffffffffff8p4, 0x1.f0420c1e63084p4},
{0x1.0p0, 0x1.fp4, 0x1.f0420c1e6308dp4},
{0x1.0p0, 0x1.ffffffffffffdp4, 0x1.001ffe003ff5fp5},
{0x1.0p0, 0x1.07ffffffffed8p5, 0x1.081f05ef4d755p5},
{0x1.0p0, 0x1.07ffffffffee8p5, 0x1.081f05ef4d764p5},
{0x1.0p0, 0x1.0fffffffffff4p5, 0x1.101e1c7371c6bp5},
{0x1.0p0, 0x1.0fffffffffffbp5, 0x1.101e1c7371c72p5},
{0x1.0p0, 0x1.17ffffffffff8p5, 0x1.181d404cf7f51p5},
{0x1.0p0, 0x1.17ffffffffffdp5, 0x1.181d404cf7f56p5},
{0x1.0p0, 0x1.1fffffffffbf2p5, 0x1.201c705fa7a27p5},
{0x1.0p0, 0x1.1fffffffffc65p5, 0x1.201c705fa7a9ap5},
{0x1.0p0, 0x1.27ffffffffe08p5, 0x1.281babadfba01p5},
{0x1.0p0, 0x1.28p5, 0x1.281babadfbbf9p5},
{0x1.0p0, 0x1.2ffffffffff64p5, 0x1.301af15517357p5},
{0x1.0p0, 0x1.2ffffffffff6cp5, 0x1.301af1551735ep5},
{0x1.0p0, 0x1.37ffffffffc78p5, 0x1.381a40895d3f5p5},
{0x1.0p0, 0x1.37ffffffffc88p5, 0x1.381a40895d406p5},
{0x1.0p0, 0x1.3fffffffffffdp5, 0x1.4019989389b2dp5},
{0x1.0p0, 0x1.4p5, 0x1.4019989389b3p5},
{0x1.0p0, 0x1.47fffffffffe8p5, 0x1.4818f8ce34e19p5},
{0x1.0p0, 0x1.47ffffffffffap5, 0x1.4818f8ce34e2cp5},
{0x1.0p0, 0x1.4fffffffffa64p5, 0x1.501860a3b54bep5},
{0x1.0p0, 0x1.4fffffffffe47p5, 0x1.501860a3b58a1p5},
{0x1.0p0, 0x1.57ffffffffff8p5, 0x1.5817cf8c4c199p5},
{0x1.0p0, 0x1.57fffffffffffp5, 0x1.5817cf8c4c1ap5},
{0x1.0p0, 0x1.5fffffffffbeep5, 0x1.6017450c8d3e7p5},
{0x1.0p0, 0x1.6p5, 0x1.6017450c8d7f9p5},
{0x1.0p0, 0x1.67fffffffffe8p5, 0x1.6816c0b405afp5},
{0x1.0p0, 0x1.68p5, 0x1.6816c0b405b09p5},
{0x1.0p0, 0x1.6fffffffffb78p5, 0x1.7016421c06043p5},
{0x1.0p0, 0x1.7p5, 0x1.7016421c064cbp5},
{0x1.0p0, 0x1.77ffffffffffp5, 0x1.7815c8e69cc37p5},
{0x1.0p0, 0x1.77ffffffffffcp5, 0x1.7815c8e69cc43p5},
{0x1.0p0, 0x1.7ffffffffffffp5, 0x1.801554bda99c5p5},
{0x1.0p0, 0x1.87fffffffffdp5, 0x1.8814e55214271p5},
{0x1.0p0, 0x1.87ffffffffffcp5, 0x1.8814e5521429ep5},
{0x1.0p0, 0x1.8ffffffffffe8p5, 0x1.90147a5b16ce5p5},
{0x1.0p0, 0x1.8fffffffffffcp5, 0x1.90147a5b16cfap5},
{0x1.0p0, 0x1.97ffffffffffp5, 0x1.98141395a0592p5},
{0x1.0p0, 0x1.97fffffffffffp5, 0x1.98141395a05a1p5},
{0x1.0p0, 0x1.9fffffffff8f4p5, 0x1.a013b0c3c7377p5},
{0x1.0p0, 0x1.9fffffffffb18p5, 0x1.a013b0c3c759bp5},
{0x1.0p0, 0x1.a7fffffffffdp5, 0x1.a81351ac4f317p5},
{0x1.0p0, 0x1.a7ffffffffffp5, 0x1.a81351ac4f338p5},
{0x1.0p0, 0x1.afffffffff698p5, 0x1.b012f61a35d98p5},
{0x1.0p0, 0x1.bp5, 0x1.b012f61a367p5},
{0x1.0p0, 0x1.b7ffffffff85p5, 0x1.b8129ddc56b26p5},
{0x1.0p0, 0x1.b7ffffffff87p5, 0x1.b8129ddc56b45p5},
{0x1.0p0, 0x1.bfffffffffffdp5, 0x1.c01248c50d99cp5},
{0x1.0p0, 0x1.bfffffffffffep5, 0x1.c01248c50d99cp5},
{0x1.0p0, 0x1.c7ffffffffedp5, 0x1.c811f6a9e9676p5},
{0x1.0p0, 0x1.c8p5, 0x1.c811f6a9e97a6p5},
{0x1.0p0, 0x1.cffffffffffe8p5, 0x1.d011a7636789ep5},
{0x1.0p0, 0x1.d7ffffffffffp5, 0x1.d8115accb20f3p5},
{0x1.0p0, 0x1.d8p5, 0x1.d8115accb2103p5},
{0x1.0p0, 0x1.dfffffffffebcp5, 0x1.e01110c367a41p5},
{0x1.0p0, 0x1.ep5, 0x1.e01110c367b85p5},
{0x1.0p0, 0x1.e7fffffffffdp5, 0x1.e810c927681fap5},
{0x1.0p0, 0x1.e8p5, 0x1.e810c9276822ap5},
{0x1.0p0, 0x1.efffffffff7f8p5, 0x1.f01083daa4dadp5},
{0x1.0p0, 0x1.fp5, 0x1.f01083daa55b5p5},
{0x1.0p0, 0x1.f7ffffffffffp5, 0x1.f81040c0f9c6p5},
{0x1.0p0, 0x1.f8p5, 0x1.f81040c0f9c71p5},
{0x1.0p0, 0x1.fffffffffffffp5, 0x1.0007ffe000fffp6},
{0x1.0p0, 0x1.03fffffffffdp6, 0x1.0407e05f7d188p6},
{0x1.0p0, 0x1.03ffffffffffbp6, 0x1.0407e05f7d1b4p6},
{0x1.0p0, 0x1.07ffffffff7f8p6, 0x1.0807c1d34edd5p6},
{0x1.0p0, 0x1.07ffffffff808p6, 0x1.0807c1d34ede4p6},
{0x1.0p0, 0x1.0bffffffff65p6, 0x1.0c07a430870e5p6},
{0x1.0p0, 0x1.0bffffffff67p6, 0x1.0c07a43087104p6},
{0x1.0p0, 0x1.0fffffffffc54p6, 0x1.1007876cda509p6},
{0x1.0p0, 0x1.0fffffffffe0dp6, 0x1.1007876cda6c2p6},
{0x1.0p0, 0x1.13fffffffffdp6, 0x1.14076b7e954b4p6},
{0x1.0p0, 0x1.13ffffffffffep6, 0x1.14076b7e954e3p6},
{0x1.0p0, 0x1.17ffffffffff8p6, 0x1.1807505c9310dp6},
{0x1.0p0, 0x1.18p6, 0x1.1807505c93116p6},
{0x1.0p0, 0x1.1bfffffffecbp6, 0x1.1c0735fe3197ap6},
{0x1.0p0, 0x1.1bffffffff1dbp6, 0x1.1c0735fe31ea5p6},
{0x1.0p0, 0x1.1ffffffffebcap6, 0x1.20071c5b4ce64p6},
{0x1.0p0, 0x1.1fffffffffaf1p6, 0x1.20071c5b4dd8bp6},
{0x1.0p0, 0x1.23ffffffff83p6, 0x1.2407036c309fdp6},
{0x1.0p0, 0x1.23ffffffff85p6, 0x1.2407036c30a1cp6},
{0x1.0p0, 0x1.27ffffffffba8p6, 0x1.2806eb2991e76p6},
{0x1.0p0, 0x1.28p6, 0x1.2806eb29922cep6},
{0x1.0p0, 0x1.2bfffffffff7p6, 0x1.2c06d38c8b4ffp6},
{0x1.0p0, 0x1.2bfffffffff9p6, 0x1.2c06d38c8b52p6},
{0x1.0p0, 0x1.2fffffffffff4p6, 0x1.3006bc8e938c8p6},
{0x1.0p0, 0x1.2fffffffffffcp6, 0x1.3006bc8e938cfp6},
{0x1.0p0, 0x1.33ffffffff87p6, 0x1.3406a6297821ep6},
{0x1.0p0, 0x1.33ffffffff89p6, 0x1.3406a6297823dp6},
{0x1.0p0, 0x1.37ffffffff9d8p6, 0x1.380690575943dp6},
{0x1.0p0, 0x1.37ffffffff9eap6, 0x1.380690575944fp6},
{0x1.0p0, 0x1.3bffffffffffp6, 0x1.3c067b12a2013p6},
{0x1.0p0, 0x1.3cp6, 0x1.3c067b12a2024p6},
{0x1.0p0, 0x1.3fffffffffe19p6, 0x1.40066656044ep6},
{0x1.0p0, 0x1.4p6, 0x1.40066656046c7p6},
{0x1.0p0, 0x1.43ffffffff1dp6, 0x1.4406521c75c3p6},
{0x1.0p0, 0x1.43ffffffffccfp6, 0x1.4406521c7672fp6},
{0x1.0p0, 0x1.47ffffffff8a8p6, 0x1.48063e612ce7ap6},
{0x1.0p0, 0x1.47ffffffffcb9p6, 0x1.48063e612d28bp6},
{0x1.0p0, 0x1.4bfffffffe1fp6, 0x1.4c062b1f96823p6},
{0x1.0p0, 0x1.4cp6, 0x1.4c062b1f98633p6},
{0x1.0p0, 0x1.4ffffffffde04p6, 0x1.500618535d07dp6},
{0x1.0p0, 0x1.5p6, 0x1.500618535f279p6},
{0x1.0p0, 0x1.53fffffffef1p6, 0x1.540605f85c637p6},
{0x1.0p0, 0x1.53ffffffffdf3p6, 0x1.540605f85d51ap6},
{0x1.0p0, 0x1.57ffffffffff8p6, 0x1.5805f40aa0595p6},
{0x1.0p0, 0x1.5bffffffffffp6, 0x1.5c05e286636b5p6},
{0x1.0p0, 0x1.5bfffffffffffp6, 0x1.5c05e286636c4p6},
{0x1.0p0, 0x1.5ffffffffd9cep6, 0x1.6005d1680baa2p6},
{0x1.0p0, 0x1.5fffffffff873p6, 0x1.6005d1680d947p6},
{0x1.0p0, 0x1.63ffffffffa5p6, 0x1.6405c0ac30a35p6},
{0x1.0p0, 0x1.63ffffffffa7p6, 0x1.6405c0ac30a56p6},
{0x1.0p0, 0x1.67ffffffff988p6, 0x1.6805b04f83ac3p6},
{0x1.0p0, 0x1.68p6, 0x1.6805b04f8413bp6},
{0x1.0p0, 0x1.6bfffffffffep6, 0x1.6c05a04ee40c3p6},
{0x1.0p0, 0x1.6cp6, 0x1.6c05a04ee40e3p6},
{0x1.0p0, 0x1.6fffffffff018p6, 0x1.700590a74f9b5p6},
{0x1.0p0, 0x1.6fffffffffbe2p6, 0x1.700590a75057fp6},
{0x1.0p0, 0x1.73ffffffff4ap6, 0x1.74058155e9b72p6},
{0x1.0p0, 0x1.74p6, 0x1.74058155ea6d2p6},
{0x1.0p0, 0x1.77ffffffffffp6, 0x1.78057257f1868p6},
{0x1.0p0, 0x1.78p6, 0x1.78057257f1878p6},
{0x1.0p0, 0x1.7bfffffffffep6, 0x1.7c0563aac389bp6},
{0x1.0p0, 0x1.7bfffffffffe4p6, 0x1.7c0563aac389fp6},
{0x1.0p0, 0x1.7ffffffffffffp6, 0x1.8005554bda349p6},
{0x1.0p0, 0x1.8p6, 0x1.8005554bda34bp6},
{0x1.0p0, 0x1.83fffffffffap6, 0x1.84054738c9dcdp6},
{0x1.0p0, 0x1.84p6, 0x1.84054738c9e2dp6},
{0x1.0p0, 0x1.87ffffffff09p6, 0x1.8805396f3f494p6},
{0x1.0p0, 0x1.87ffffffff0bp6, 0x1.8805396f3f4b5p6},
{0x1.0p0, 0x1.8bfffffffffep6, 0x1.8c052bed02f7ap6},
{0x1.0p0, 0x1.8cp6, 0x1.8c052bed02f9bp6},
{0x1.0p0, 0x1.8fffffffff7c8p6, 0x1.90051eafee07bp6},
{0x1.0p0, 0x1.9p6, 0x1.90051eafee8b3p6},
{0x1.0p1, 0x1.fffffffffdcb5p-1, 0x1.1e3779b97f0b5p1},
{0x1.0p1, 0x1.ffffffffffab5p0, 0x1.6a09e667f39edp1},
{0x1.0p1, 0x1.7ffffffffffffp1, 0x1.cd82b446159f2p1},
{0x1.0p1, 0x1.8p1, 0x1.cd82b446159f3p1},
{0x1.0p1, 0x1.ffffffffffffbp1, 0x1.1e3779b97f4a6p2},
{0x1.0p1, 0x1.3fffffffffffdp2, 0x1.58a68a4a8d9fp2},
{0x1.0p1, 0x1.3fffffffffffep2, 0x1.58a68a4a8d9f1p2},
{0x1.0p1, 0x1.7ffffffffffffp2, 0x1.94c583ada5b51p2},
{0x1.0p1, 0x1.bfffffffffffep2, 0x1.d1ed52076fbe7p2},
{0x1.0p1, 0x1.cp2, 0x1.d1ed52076fbe9p2},
{0x1.0p1, 0x1.ffffffffffffdp2, 0x1.07e0f66afed06p3},
{0x1.0p1, 0x1.1fffffffffff2p3, 0x1.2706821902e8cp3},
{0x1.0p1, 0x1.2p3, 0x1.2706821902e9ap3},
{0x1.0p1, 0x1.3fffffffffffdp3, 0x1.465655f122ff3p3},
{0x1.0p1, 0x1.4p3, 0x1.465655f122ff6p3},
{0x1.0p1, 0x1.5ffffffffffd6p3, 0x1.65c55827df1a8p3},
{0x1.0p1, 0x1.7ffffffffffffp3, 0x1.854bfb363dc38p3},
{0x1.0p1, 0x1.8p3, 0x1.854bfb363dc39p3},
{0x1.0p1, 0x1.9ffffffffffe4p3, 0x1.a4e4efeda34c2p3},
{0x1.0p1, 0x1.ap3, 0x1.a4e4efeda34dep3},
{0x1.0p1, 0x1.bfffffffffffep3, 0x1.c48c6001f0abdp3},
{0x1.0p1, 0x1.dfffffffffffcp3, 0x1.e43f746f77956p3},
{0x1.0p1, 0x1.ep3, 0x1.e43f746f7795bp3},
{0x1.0p1, 0x1.fffffffffffffp3, 0x1.01fe03f61badp4},
{0x1.0p1, 0x1.0ffffffffffc4p4, 0x1.11e039f40ee2ap4},
{0x1.0p1, 0x1.0ffffffffffc7p4, 0x1.11e039f40ee2dp4},
{0x1.0p1, 0x1.1fffffffffffap4, 0x1.21c5b70d9f81dp4},
{0x1.0p1, 0x1.2fffffffffffcp4, 0x1.31adf859f9e5ap4},
{0x1.0p1, 0x1.2fffffffffffep4, 0x1.31adf859f9e5cp4},
{0x1.0p1, 0x1.3ffffffffffe5p4, 0x1.419894c2329d5p4},
{0x1.0p1, 0x1.3ffffffffffe7p4, 0x1.419894c2329d8p4},
{0x1.0p1, 0x1.4fffffffffff4p4, 0x1.518536f3ca668p4},
{0x1.0p1, 0x1.5p4, 0x1.518536f3ca675p4},
{0x1.0p1, 0x1.5ffffffffff7ep4, 0x1.617398f2aa9c6p4},
{0x1.0p1, 0x1.5ffffffffff8dp4, 0x1.617398f2aa9d5p4},
{0x1.0p1, 0x1.6ffffffffffb8p4, 0x1.716380ce70352p4},
{0x1.0p1, 0x1.7p4, 0x1.716380ce7039ap4},
{0x1.0p1, 0x1.7ffffffffff9bp4, 0x1.8154be27734c1p4},
{0x1.0p1, 0x1.8p4, 0x1.8154be2773526p4},
{0x1.0p1, 0x1.8ffffffffffe8p4, 0x1.9147284a4142fp4},
{0x1.0p1, 0x1.8ffffffffffffp4, 0x1.9147284a41446p4},
{0x1.0p1, 0x1.9fffffffffff4p4, 0x1.a13a9cb996644p4},
{0x1.0p1, 0x1.9ffffffffffffp4, 0x1.a13a9cb99664fp4},
{0x1.0p1, 0x1.affffffffff58p4, 0x1.b12efe0a8f113p4},
{0x1.0p1, 0x1.affffffffffd2p4, 0x1.b12efe0a8f18dp4},
{0x1.0p1, 0x1.bfffffffffffep4, 0x1.c12432fec0327p4},
{0x1.0p1, 0x1.cp4, 0x1.c12432fec0329p4},
{0x1.0p1, 0x1.cffffffffffe8p4, 0x1.d11a25cd6ed78p4},
{0x1.0p1, 0x1.dp4, 0x1.d11a25cd6ed91p4},
{0x1.0p1, 0x1.dffffffffffbcp4, 0x1.e110c39105f6bp4},
{0x1.0p1, 0x1.ep4, 0x1.e110c39105fafp4},
{0x1.0p1, 0x1.effffffffffe8p4, 0x1.f107fbd0adcf1p4},
{0x1.0p1, 0x1.efffffffffff8p4, 0x1.f107fbd0addp4},
{0x1.0p1, 0x1.ffffffffffeafp4, 0x1.007fe00ff5fc8p5},
{0x1.0p1, 0x1.07fffffffffe8p5, 0x1.087c01e7d5092p5},
{0x1.0p1, 0x1.08p5, 0x1.087c01e7d50abp5},
{0x1.0p1, 0x1.0fffffffffff4p5, 0x1.10785dd689a1cp5},
{0x1.0p1, 0x1.0fffffffffffbp5, 0x1.10785dd689a23p5},
{0x1.0p1, 0x1.17ffffffffed8p5, 0x1.1874eee5c5cb1p5},
{0x1.0p1, 0x1.17ffffffffee8p5, 0x1.1874eee5c5cc2p5},
{0x1.0p1, 0x1.1ffffffffff92p5, 0x1.2071b0abcd7cap5},
{0x1.0p1, 0x1.1ffffffffff99p5, 0x1.2071b0abcd7d1p5},
{0x1.0p1, 0x1.27ffffffffea8p5, 0x1.286e9f388de9fp5},
{0x1.0p1, 0x1.28p5, 0x1.286e9f388dff7p5},
{0x1.0p1, 0x1.2fffffffffffcp5, 0x1.306bb705ae7bfp5},
{0x1.0p1, 0x1.2ffffffffffffp5, 0x1.306bb705ae7c3p5},
{0x1.0p1, 0x1.37ffffffffff8p5, 0x1.3868f4e9108b9p5},
{0x1.0p1, 0x1.38p5, 0x1.3868f4e9108c1p5},
{0x1.0p1, 0x1.3fffffffffffdp5, 0x1.4066560954a8bp5},
{0x1.0p1, 0x1.47ffffffffe28p5, 0x1.4863d7d40ad39p5},
{0x1.0p1, 0x1.48p5, 0x1.4863d7d40af11p5},
{0x1.0p1, 0x1.4fffffffffe14p5, 0x1.506177f548fcfp5},
{0x1.0p1, 0x1.5p5, 0x1.506177f5491bbp5},
{0x1.0p1, 0x1.57ffffffffeb8p5, 0x1.585f34506bafbp5},
{0x1.0p1, 0x1.58p5, 0x1.585f34506bc43p5},
{0x1.0p1, 0x1.5fffffffffffdp5, 0x1.605d0af9d3a42p5},
{0x1.0p1, 0x1.5fffffffffffep5, 0x1.605d0af9d3a42p5},
{0x1.0p1, 0x1.67ffffffffda8p5, 0x1.685afa317791bp5},
{0x1.0p1, 0x1.68p5, 0x1.685afa3177b73p5},
{0x1.0p1, 0x1.6fffffffffff8p5, 0x1.7059005e2c015p5},
{0x1.0p1, 0x1.6ffffffffffffp5, 0x1.7059005e2c01dp5},
{0x1.0p1, 0x1.77ffffffffffp5, 0x1.78571c0982328p5},
{0x1.0p1, 0x1.78p5, 0x1.78571c0982339p5},
{0x1.0p1, 0x1.7fffffffffffdp5, 0x1.80554bdc2dc4dp5},
{0x1.0p1, 0x1.7ffffffffffffp5, 0x1.80554bdc2dc4ep5},
{0x1.0p1, 0x1.87fffffffffdp5, 0x1.88538e9ad8dacp5},
{0x1.0p1, 0x1.87fffffffffffp5, 0x1.88538e9ad8ddbp5},
{0x1.0p1, 0x1.8fffffffffe68p5, 0x1.9051e3235a2cp5},
{0x1.0p1, 0x1.9p5, 0x1.9051e3235a458p5},
{0x1.0p1, 0x1.97ffffffffffp5, 0x1.9850486a3f17p5},
{0x1.0p1, 0x1.97fffffffffffp5, 0x1.9850486a3f17fp5},
{0x1.0p1, 0x1.9fffffffffff4p5, 0x1.a04ebd789d00cp5},
{0x1.0p1, 0x1.ap5, 0x1.a04ebd789d019p5},
{0x1.0p1, 0x1.a7ffffffffe1p5, 0x1.a84d416a2354dp5},
{0x1.0p1, 0x1.a8p5, 0x1.a84d416a2373dp5},
{0x1.0p1, 0x1.afffffffffed8p5, 0x1.b04bd36b639fbp5},
{0x1.0p1, 0x1.affffffffff43p5, 0x1.b04bd36b63a66p5},
{0x1.0p1, 0x1.b7ffffffffd7p5, 0x1.b84a72b848951p5},
{0x1.0p1, 0x1.b7ffffffffe2bp5, 0x1.b84a72b848a0cp5},
{0x1.0p1, 0x1.bfffffffffe3ep5, 0x1.c0491e9ab90fdp5},
{0x1.0p1, 0x1.cp5, 0x1.c0491e9ab92bfp5},
{0x1.0p1, 0x1.c7fffffffffdp5, 0x1.c847d6695dbc5p5},
{0x1.0p1, 0x1.c8p5, 0x1.c847d6695dbf6p5},
{0x1.0p1, 0x1.cfffffffffed8p5, 0x1.d0469986884d6p5},
{0x1.0p1, 0x1.cfffffffffee8p5, 0x1.d0469986884e5p5},
{0x1.0p1, 0x1.d7ffffffffdfp5, 0x1.d845675f37721p5},
{0x1.0p1, 0x1.d8p5, 0x1.d845675f37931p5},
{0x1.0p1, 0x1.dfffffffffe5cp5, 0x1.e0443f6a33104p5},
{0x1.0p1, 0x1.dffffffffffffp5, 0x1.e0443f6a332a7p5},
{0x1.0p1, 0x1.e7fffffffff05p5, 0x1.e84321273f31ep5},
{0x1.0p1, 0x1.e7fffffffff1p5, 0x1.e84321273f328p5},
{0x1.0p1, 0x1.efffffffffff8p5, 0x1.f0420c1e63084p5},
{0x1.0p1, 0x1.fp5, 0x1.f0420c1e6308dp5},
{0x1.0p1, 0x1.f7ffffffffc3p5, 0x1.f840ffdf40effp5},
{0x1.0p1, 0x1.f7fffffffff08p5, 0x1.f840ffdf411d7p5},
{0x1.0p1, 0x1.ffffffffffffdp5, 0x1.001ffe003ff5fp6},
{0x1.0p1, 0x1.03fffffffffdp6, 0x1.041f800f9f928p6},
{0x1.0p1, 0x1.03ffffffffffap6, 0x1.041f800f9f953p6},
{0x1.0p1, 0x1.07ffffffffed8p6, 0x1.081f05ef4d755p6},
{0x1.0p1, 0x1.07ffffffffee8p6, 0x1.081f05ef4d764p6},
{0x1.0p1, 0x1.0bfffffffff5p6, 0x1.0c1e8f739cdcap6},
{0x1.0p1, 0x1.0bfffffffff7p6, 0x1.0c1e8f739cde9p6},
{0x1.0p1, 0x1.0fffffffffff4p6, 0x1.101e1c7371c6bp6},
{0x1.0p1, 0x1.0fffffffffffbp6, 0x1.101e1c7371c72p6},
{0x1.0p1, 0x1.13fffffffffdp6, 0x1.141dacc811a34p6},
{0x1.0p1, 0x1.13ffffffffffcp6, 0x1.141dacc811a6p6},
{0x1.0p1, 0x1.17ffffffffff8p6, 0x1.181d404cf7f51p6},
{0x1.0p1, 0x1.17ffffffffffdp6, 0x1.181d404cf7f56p6},
{0x1.0p1, 0x1.1bffffffffffp6, 0x1.1c1cd6dfae4a5p6},
{0x1.0p1, 0x1.1bffffffffffep6, 0x1.1c1cd6dfae4b4p6},
{0x1.0p1, 0x1.1fffffffffbf2p6, 0x1.201c705fa7a27p6},
{0x1.0p1, 0x1.1fffffffffc65p6, 0x1.201c705fa7a9ap6},
{0x1.0p1, 0x1.23fffffffffdp6, 0x1.241c0cae201cap6},
{0x1.0p1, 0x1.23ffffffffffp6, 0x1.241c0cae201ebp6},
{0x1.0p1, 0x1.27ffffffffe08p6, 0x1.281babadfba01p6},
{0x1.0p1, 0x1.28p6, 0x1.281babadfbbf9p6},
{0x1.0p1, 0x1.2bffffffffc1p6, 0x1.2c1b4d43ac4cfp6},
{0x1.0p1, 0x1.2bffffffffc3p6, 0x1.2c1b4d43ac4eep6},
{0x1.0p1, 0x1.2ffffffffff64p6, 0x1.301af15517357p6},
{0x1.0p1, 0x1.2ffffffffff6cp6, 0x1.301af1551735ep6},
{0x1.0p1, 0x1.33ffffffffadp6, 0x1.341a97c97b22ep6},
{0x1.0p1, 0x1.33ffffffffafp6, 0x1.341a97c97b24fp6},
{0x1.0p1, 0x1.37ffffffffc78p6, 0x1.381a40895d3f5p6},
{0x1.0p1, 0x1.37ffffffffc88p6, 0x1.381a40895d406p6},
{0x1.0p1, 0x1.3bffffffffffp6, 0x1.3c19eb7e71afcp6},
{0x1.0p1, 0x1.3bfffffffffffp6, 0x1.3c19eb7e71b0cp6},
{0x1.0p1, 0x1.3fffffffffffdp6, 0x1.4019989389b2dp6},
{0x1.0p1, 0x1.4p6, 0x1.4019989389b3p6},
{0x1.0p1, 0x1.43fffffffffdp6, 0x1.441947b4829e8p6},
{0x1.0p1, 0x1.43ffffffffff8p6, 0x1.441947b482a11p6},
{0x1.0p1, 0x1.47fffffffffe8p6, 0x1.4818f8ce34e19p6},
{0x1.0p1, 0x1.47ffffffffffap6, 0x1.4818f8ce34e2cp6},
{0x1.0p1, 0x1.4bffffffffffp6, 0x1.4c18abce6501fp6},
{0x1.0p1, 0x1.4bffffffffffcp6, 0x1.4c18abce6502cp6},
{0x1.0p1, 0x1.4fffffffffa64p6, 0x1.501860a3b54bep6},
{0x1.0p1, 0x1.4fffffffffe47p6, 0x1.501860a3b58a1p6},
{0x1.0p1, 0x1.53ffffffffd5p6, 0x1.5418173d9a501p6},
{0x1.0p1, 0x1.53ffffffffd7p6, 0x1.5418173d9a522p6},
{0x1.0p1, 0x1.57ffffffffff8p6, 0x1.5817cf8c4c199p6},
{0x1.0p1, 0x1.57fffffffffffp6, 0x1.5817cf8c4c1ap6},
{0x1.0p1, 0x1.5bffffffff83p6, 0x1.5c178980bc34bp6},
{0x1.0p1, 0x1.5bffffffff988p6, 0x1.5c178980bc4a3p6},
{0x1.0p1, 0x1.5fffffffffbeep6, 0x1.6017450c8d3e7p6},
{0x1.0p1, 0x1.6p6, 0x1.6017450c8d7f9p6},
{0x1.0p1, 0x1.63fffffffffdp6, 0x1.6417022204f99p6},
{0x1.0p1, 0x1.67fffffffffe8p6, 0x1.6816c0b405afp6},
{0x1.0p1, 0x1.68p6, 0x1.6816c0b405b09p6},
{0x1.0p1, 0x1.6bfffffffffep6, 0x1.6c1680b6059e8p6},
{0x1.0p1, 0x1.6cp6, 0x1.6c1680b605a08p6},
{0x1.0p1, 0x1.6fffffffffb78p6, 0x1.7016421c06043p6},
{0x1.0p1, 0x1.7p6, 0x1.7016421c064cbp6},
{0x1.0p1, 0x1.73fffffffffap6, 0x1.741604da8d2b9p6},
{0x1.0p1, 0x1.73ffffffffff8p6, 0x1.741604da8d311p6},
{0x1.0p1, 0x1.77ffffffffffp6, 0x1.7815c8e69cc37p6},
{0x1.0p1, 0x1.77ffffffffffcp6, 0x1.7815c8e69cc43p6},
{0x1.0p1, 0x1.7bfffffffffep6, 0x1.7c158e35adde4p6},
{0x1.0p1, 0x1.7bfffffffffe8p6, 0x1.7c158e35addecp6},
{0x1.0p1, 0x1.7ffffffffffffp6, 0x1.801554bda99c5p6},
{0x1.0p1, 0x1.83ffffffffdap6, 0x1.84151c74e35e4p6},
{0x1.0p1, 0x1.83ffffffffdep6, 0x1.84151c74e3625p6},
{0x1.0p1, 0x1.87fffffffffdp6, 0x1.8814e55214271p6},
{0x1.0p1, 0x1.87ffffffffffcp6, 0x1.8814e5521429ep6},
{0x1.0p1, 0x1.8bfffffffffep6, 0x1.8c14af4c540b6p6},
{0x1.0p1, 0x1.8bffffffffff6p6, 0x1.8c14af4c540cdp6},
{0x1.0p1, 0x1.8ffffffffffe8p6, 0x1.90147a5b16ce5p6},
{0x1.0p1, 0x1.8fffffffffffcp6, 0x1.90147a5b16cfap6},
{0x1.8p1, 0x1.ffffffffffffdp-1, 0x1.94c583ada5b53p1},
{0x1.8p1, 0x1.0p1, 0x1.cd82b446159f3p1},
{0x1.8p1, 0x1.7fffffffffff7p1, 0x1.0f876ccdf6cd6p2},
{0x1.8p1, 0x1.8p1, 0x1.0f876ccdf6cd9p2},
{0x1.8p1, 0x1.fffffffffffffp1, 0x1.4p2},
{0x1.8p1, 0x1.3ffffffffffe1p2, 0x1.752e50db3a387p2},
{0x1.8p1, 0x1.4p2, 0x1.752e50db3a3a2p2},
{0x1.8p1, 0x1.7ffffffffffffp2, 0x1.ad5336963eefap2},
{0x1.8p1, 0x1.bfffffffffffep2, 0x1.e768d399dc46dp2},
{0x1.8p1, 0x1.bffffffffffffp2, 0x1.e768d399dc46fp2},
{0x1.8p1, 0x1.fffffffffffffp2, 0x1.11687a8ae14a3p3},
{0x1.8p1, 0x1.1fffffffffff2p3, 0x1.2f9422c23c47p3},
{0x1.8p1, 0x1.1fffffffffff7p3, 0x1.2f9422c23c475p3},
{0x1.8p1, 0x1.3fffffffffff1p3, 0x1.4e16fdacff928p3},
{0x1.8p1, 0x1.3fffffffffff4p3, 0x1.4e16fdacff92bp3},
{0x1.8p1, 0x1.5ffffffffffffp3, 0x1.6cdb2bbb212ebp3},
{0x1.8p1, 0x1.7fffffffffffdp3, 0x1.8bd171a07e388p3},
{0x1.8p1, 0x1.7ffffffffffffp3, 0x1.8bd171a07e389p3},
{0x1.8p1, 0x1.9ffffffffffe4p3, 0x1.aaeee979b481cp3},
{0x1.8p1, 0x1.9ffffffffffecp3, 0x1.aaeee979b4825p3},
{0x1.8p1, 0x1.bffffffffffeep3, 0x1.ca2b9714180e5p3},
{0x1.8p1, 0x1.cp3, 0x1.ca2b9714180f7p3},
{0x1.8p1, 0x1.dfffffffffffcp3, 0x1.e98180e9b47edp3},
{0x1.8p1, 0x1.dfffffffffffep3, 0x1.e98180e9b47efp3},
{0x1.8p1, 0x1.fffffffffffffp3, 0x1.04760c95db31p4},
{0x1.8p1, 0x1.0fffffffffff4p4, 0x1.1433ec467efefp4},
{0x1.8p1, 0x1.1ffffffffffeap4, 0x1.23f8fc68ae515p4},
{0x1.8p1, 0x1.2p4, 0x1.23f8fc68ae52bp4},
{0x1.8p1, 0x1.2fffffffffffcp4, 0x1.33c42213ee0c5p4},
{0x1.8p1, 0x1.3p4, 0x1.33c42213ee0c9p4},
{0x1.8p1, 0x1.3ffffffffffd9p4, 0x1.439479381ec96p4},
{0x1.8p1, 0x1.3fffffffffff6p4, 0x1.439479381ecb3p4},
{0x1.8p1, 0x1.4ffffffffffc4p4, 0x1.53694801747d4p4},
{0x1.8p1, 0x1.4ffffffffffccp4, 0x1.53694801747dcp4},
{0x1.8p1, 0x1.5ffffffffffbep4, 0x1.6341f58bad9d2p4},
{0x1.8p1, 0x1.5ffffffffffc2p4, 0x1.6341f58bad9d7p4},
{0x1.8p1, 0x1.6fffffffffff8p4, 0x1.731e02ed21f18p4},
{0x1.8p1, 0x1.6ffffffffffffp4, 0x1.731e02ed21f2p4},
{0x1.8p1, 0x1.7fffffffffffdp4, 0x1.82fd05f129836p4},
{0x1.8p1, 0x1.7ffffffffffffp4, 0x1.82fd05f129837p4},
{0x1.8p1, 0x1.8ffffffffffa8p4, 0x1.92dea50d28578p4},
{0x1.8p1, 0x1.8ffffffffffffp4, 0x1.92dea50d285cep4},
{0x1.8p1, 0x1.9ffffffffffe4p4, 0x1.a2c2943e2866p4},
{0x1.8p1, 0x1.9fffffffffffcp4, 0x1.a2c2943e28678p4},
{0x1.8p1, 0x1.afffffffffff8p4, 0x1.b2a892946f42dp4},
{0x1.8p1, 0x1.afffffffffffep4, 0x1.b2a892946f434p4},
{0x1.8p1, 0x1.bffffffffffeep4, 0x1.c2906842b6bf3p4},
{0x1.8p1, 0x1.bfffffffffff2p4, 0x1.c2906842b6bf8p4},
{0x1.8p1, 0x1.cffffffffffe8p4, 0x1.d279e51208c72p4},
{0x1.8p1, 0x1.dp4, 0x1.d279e51208c8ap4},
{0x1.8p1, 0x1.dfffffffffff4p4, 0x1.e264df234beddp4},
{0x1.8p1, 0x1.dfffffffffffcp4, 0x1.e264df234bee4p4},
{0x1.8p1, 0x1.efffffffffff8p4, 0x1.f25131ed54d64p4},
{0x1.8p1, 0x1.fp4, 0x1.f25131ed54d6cp4},
{0x1.8p1, 0x1.fffffffffffffp4, 0x1.011f5eb54147p5},
{0x1.8p1, 0x1.07fffffffff88p5, 0x1.0916b2b5fff3ep5},
{0x1.8p1, 0x1.07fffffffffaap5, 0x1.0916b2b5fff6p5},
{0x1.8p1, 0x1.0ffffffffffc4p5, 0x1.110e8885865b8p5},
{0x1.8p1, 0x1.0ffffffffffccp5, 0x1.110e8885865c1p5},
{0x1.8p1, 0x1.17fffffffff58p5, 0x1.1906d51932b7ep5},
{0x1.8p1, 0x1.17fffffffff77p5, 0x1.1906d51932b9dp5},
{0x1.8p1, 0x1.1fffffffffffap5, 0x1.20ff8e9d967d6p5},
{0x1.8p1, 0x1.1fffffffffffep5, 0x1.20ff8e9d967dbp5},
{0x1.8p1, 0x1.27fffffffffc8p5, 0x1.28f8ac4cd98f2p5},
{0x1.8p1, 0x1.27fffffffffd8p5, 0x1.28f8ac4cd9903p5},
{0x1.8p1, 0x1.2ffffffffff7cp5, 0x1.30f2264b9c502p5},
{0x1.8p1, 0x1.2ffffffffffafp5, 0x1.30f2264b9c535p5},
{0x1.8p1, 0x1.37ffffffffff8p5, 0x1.38ebf58b30cb4p5},
{0x1.8p1, 0x1.37fffffffffffp5, 0x1.38ebf58b30cbcp5},
{0x1.8p1, 0x1.3fffffffffffdp5, 0x1.40e613b03f1dcp5},
{0x1.8p1, 0x1.3ffffffffffffp5, 0x1.40e613b03f1dfp5},
{0x1.8p1, 0x1.47fffffffffa1p5, 0x1.48e07afd169d5p5},
{0x1.8p1, 0x1.47fffffffffa8p5, 0x1.48e07afd169dbp5},
{0x1.8p1, 0x1.4ffffffffff84p5, 0x1.50db263f101e3p5},
{0x1.8p1, 0x1.4ffffffffff8cp5, 0x1.50db263f101ecp5},
{0x1.8p1, 0x1.57ffffffffff8p5, 0x1.58d610be831eep5},
{0x1.8p1, 0x1.58p5, 0x1.58d610be831f7p5},
{0x1.8p1, 0x1.5fffffffffffap5, 0x1.60d13630e611p5},
{0x1.8p1, 0x1.5fffffffffffep5, 0x1.60d13630e6113p5},
{0x1.8p1, 0x1.67fffffffffe8p5, 0x1.68cc92acc47abp5},
{0x1.8p1, 0x1.68p5, 0x1.68cc92acc47c3p5},
{0x1.8p1, 0x1.6fffffffffff8p5, 0x1.70c8229f43a38p5},
{0x1.8p1, 0x1.6fffffffffffap5, 0x1.70c8229f43a3ap5},
{0x1.8p1, 0x1.77ffffffffffp5, 0x1.78c3e2c2fb433p5},
{0x1.8p1, 0x1.77ffffffffffep5, 0x1.78c3e2c2fb441p5},
{0x1.8p1, 0x1.7ffffffffffffp5, 0x1.80bfd017f10a6p5},
{0x1.8p1, 0x1.87fffffffff5p5, 0x1.88bbe7dc8d9ap5},
{0x1.8p1, 0x1.88p5, 0x1.88bbe7dc8da5p5},
{0x1.8p1, 0x1.8ffffffffffe8p5, 0x1.90b8278768b67p5},
{0x1.8p1, 0x1.9p5, 0x1.90b8278768b8p5},
{0x1.8p1, 0x1.97fffffffff2bp5, 0x1.98b48cc1ce669p5},
{0x1.8p1, 0x1.97fffffffff3p5, 0x1.98b48cc1ce66dp5},
{0x1.8p1, 0x1.9ffffffffff34p5, 0x1.a0b11562e5efcp5},
{0x1.8p1, 0x1.ap5, 0x1.a0b11562e5fc8p5},
{0x1.8p1, 0x1.a7fffffffffdp5, 0x1.a8adbf6b63874p5},
{0x1.8p1, 0x1.a8p5, 0x1.a8adbf6b638a4p5},
{0x1.8p1, 0x1.affffffffffd8p5, 0x1.b0aa8901b442cp5},
{0x1.8p1, 0x1.affffffffffe8p5, 0x1.b0aa8901b443dp5},
{0x1.8p1, 0x1.b7ffffffffffp5, 0x1.b8a7706e94761p5},
{0x1.8p1, 0x1.b7ffffffffffep5, 0x1.b8a7706e9477p5},
{0x1.8p1, 0x1.bfffffffffffep5, 0x1.c0a4741a02dcap5},
{0x1.8p1, 0x1.cp5, 0x1.c0a4741a02dcdp5},
{0x1.8p1, 0x1.c7fffffffffdp5, 0x1.c8a1928885b75p5},
{0x1.8p1, 0x1.c7ffffffffff9p5, 0x1.c8a1928885b9fp5},
{0x1.8p1, 0x1.cffffffffff28p5, 0x1.d09eca58b7d2cp5},
{0x1.8p1, 0x1.dp5, 0x1.d09eca58b7e04p5},
{0x1.8p1, 0x1.d7ffffffffffp5, 0x1.d89c1a4115253p5},
{0x1.8p1, 0x1.d8p5, 0x1.d89c1a4115264p5},
{0x1.8p1, 0x1.dfffffffffffcp5, 0x1.e099810dfefd1p5},
{0x1.8p1, 0x1.e7fffffffffdp5, 0x1.e896fd9ff2afep5},
{0x1.8p1, 0x1.e7ffffffffffap5, 0x1.e896fd9ff2b29p5},
{0x1.8p1, 0x1.effffffffff98p5, 0x1.f0948ee9ebc7bp5},
{0x1.8p1, 0x1.effffffffffcap5, 0x1.f0948ee9ebcadp5},
{0x1.8p1, 0x1.f7fffffffff7p5, 0x1.f89233efeda08p5},
{0x1.8p1, 0x1.f7fffffffffb2p5, 0x1.f89233efeda4ap5},
{0x1.8p1, 0x1.ffffffffffda9p5, 0x1.0047f5e2d7ed7p6},
{0x1.8p1, 0x1.03ffffffffedp6, 0x1.0446dac6b5468p6},
{0x1.8p1, 0x1.04p6, 0x1.0446dac6b5598p6},
{0x1.8p1, 0x1.07fffffffffe8p6, 0x1.0845c83b5eb9bp6},
{0x1.8p1, 0x1.07ffffffffff9p6, 0x1.0845c83b5ebadp6},
{0x1.8p1, 0x1.0bffffffffe9bp6, 0x1.0c44bdded82bdp6},
{0x1.8p1, 0x1.0bffffffffebp6, 0x1.0c44bdded82d1p6},
{0x1.8p1, 0x1.0fffffffffed4p6, 0x1.1043bb54e5cc9p6},
{0x1.8p1, 0x1.0ffffffffff1fp6, 0x1.1043bb54e5d14p6},
{0x1.8p1, 0x1.13ffffffffe9p6, 0x1.1442c046a0ea6p6},
{0x1.8p1, 0x1.13fffffffff5ap6, 0x1.1442c046a0f7p6},
{0x1.8p1, 0x1.17fffffffffa8p6, 0x1.1841cc62174cbp6},
{0x1.8p1, 0x1.17fffffffffb8p6, 0x1.1841cc62174dap6},
{0x1.8p1, 0x1.1bffffffffffp6, 0x1.1c40df59f1a57p6},
{0x1.8p1, 0x1.1cp6, 0x1.1c40df59f1a67p6},
{0x1.8p1, 0x1.1fffffffffffap6, 0x1.203ff8e522535p6},
{0x1.8p1, 0x1.1ffffffffffffp6, 0x1.203ff8e52253bp6},
{0x1.8p1, 0x1.23fffffffffdp6, 0x1.243f18be9a334p6},
{0x1.8p1, 0x1.23ffffffffffbp6, 0x1.243f18be9a36p6},
{0x1.8p1, 0x1.27fffffffffe8p6, 0x1.283e3ea503c63p6},
{0x1.8p1, 0x1.27ffffffffff8p6, 0x1.283e3ea503c74p6},
{0x1.8p1, 0x1.2bffffffffdfp6, 0x1.2c3d6a5a83932p6},
{0x1.8p1, 0x1.2bffffffffe1p6, 0x1.2c3d6a5a83953p6},
{0x1.8p1, 0x1.2fffffffffffcp6, 0x1.303c9ba47e6d4p6},
{0x1.8p1, 0x1.3p6, 0x1.303c9ba47e6d8p6},
{0x1.8p1, 0x1.33fffffffffdp6, 0x1.343bd24b62468p6},
{0x1.8p1, 0x1.33fffffffffffp6, 0x1.343bd24b62498p6},
{0x1.8p1, 0x1.37ffffffffff8p6, 0x1.383b0e1a75c0ap6},
{0x1.8p1, 0x1.37fffffffffffp6, 0x1.383b0e1a75c12p6},
{0x1.8p1, 0x1.3bffffffffffp6, 0x1.3c3a4edfa9748p6},
{0x1.8p1, 0x1.3bffffffffffep6, 0x1.3c3a4edfa9756p6},
{0x1.8p1, 0x1.3fffffffffd4dp6, 0x1.4039946b6d79fp6},
{0x1.8p1, 0x1.3ffffffffffffp6, 0x1.4039946b6da51p6},
{0x1.8p1, 0x1.43fffffffff9p6, 0x1.4438de908abeap6},
{0x1.8p1, 0x1.43fffffffffbp6, 0x1.4438de908ac0bp6},
{0x1.8p1, 0x1.47ffffffffd08p6, 0x1.48382d23fccedp6},
{0x1.8p1, 0x1.47fffffffffa2p6, 0x1.48382d23fcf87p6},
{0x1.8p1, 0x1.4bffffffffcebp6, 0x1.4c377ffcd212fp6},
{0x1.8p1, 0x1.4bffffffffcfp6, 0x1.4c377ffcd2133p6},
{0x1.8p1, 0x1.4ffffffffff44p6, 0x1.5036d6f40ad53p6},
{0x1.8p1, 0x1.4ffffffffff9bp6, 0x1.5036d6f40adaap6},
{0x1.8p1, 0x1.53ffffffffedp6, 0x1.543631e47c1e1p6},
{0x1.8p1, 0x1.54p6, 0x1.543631e47c311p6},
{0x1.8p1, 0x1.57ffffffffd78p6, 0x1.583590aab542dp6},
{0x1.8p1, 0x1.58p6, 0x1.583590aab56b5p6},
{0x1.8p1, 0x1.5bffffffffc7p6, 0x1.5c34f324e60eep6},
{0x1.8p1, 0x1.5bffffffffc9p6, 0x1.5c34f324e610fp6},
{0x1.8p1, 0x1.5fffffffffffdp6, 0x1.60345932c760dp6},
{0x1.8p1, 0x1.5fffffffffffep6, 0x1.60345932c760dp6},
{0x1.8p1, 0x1.63fffffffff79p6, 0x1.6433c2b58421fp6},
{0x1.8p1, 0x1.63fffffffff9p6, 0x1.6433c2b584235p6},
{0x1.8p1, 0x1.67ffffffffda8p6, 0x1.68332f8fa63a6p6},
{0x1.8p1, 0x1.67fffffffff4dp6, 0x1.68332f8fa654bp6},
{0x1.8p1, 0x1.6bfffffffffep6, 0x1.6c329fa502ccfp6},
{0x1.8p1, 0x1.6cp6, 0x1.6c329fa502cefp6},
{0x1.8p1, 0x1.6fffffffffff8p6, 0x1.703212daa75f3p6},
{0x1.8p1, 0x1.6ffffffffffffp6, 0x1.703212daa75fbp6},
{0x1.8p1, 0x1.73fffffffffap6, 0x1.74318916ca409p6},
{0x1.8p1, 0x1.74p6, 0x1.74318916ca46ap6},
{0x1.8p1, 0x1.77ffffffffffp6, 0x1.78310240ba47p6},
{0x1.8p1, 0x1.78p6, 0x1.78310240ba481p6},
{0x1.8p1, 0x1.7bfffffffffep6, 0x1.7c307e40cff7fp6},
{0x1.8p1, 0x1.7bfffffffffe4p6, 0x1.7c307e40cff83p6},
{0x1.8p1, 0x1.7fffffffffff7p6, 0x1.802ffd005ff07p6},
{0x1.8p1, 0x1.7fffffffffff9p6, 0x1.802ffd005ff0ap6},
{0x1.8p1, 0x1.83fffffffffap6, 0x1.842f7e69adc1ep6},
{0x1.8p1, 0x1.83fffffffffffp6, 0x1.842f7e69adc7dp6},
{0x1.8p1, 0x1.87fffffffffdp6, 0x1.882f0267dfef4p6},
{0x1.8p1, 0x1.88p6, 0x1.882f0267dff24p6},
{0x1.8p1, 0x1.8bfffffffffep6, 0x1.8c2e88e6f449ap6},
{0x1.8p1, 0x1.8bffffffffff6p6, 0x1.8c2e88e6f44b1p6},
{0x1.8p1, 0x1.8ffffffffffe8p6, 0x1.902e11d3b5549p6},
{0x1.8p1, 0x1.8fffffffffffep6, 0x1.902e11d3b556p6},
};
for (double[] testCase: testCases)
failures+=testHypotCase(testCase[0], testCase[1], testCase[2]);
return failures;
}
public static void main(String [] argv) {
int failures = 0;
failures += testHypot();
if (failures > 0) {
System.err.println("Testing log1p incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4074599
* @summary Tests for StrictMath.log10
* @author Joseph D. Darcy
*/
/**
* The tests in ../Math/Log10Tests.java test properties that should
* hold for any log10 implementation, including the FDLIBM-based one
* required for StrictMath.log10. Therefore, the test cases in
* ../Math/Log10Tests.java are run against both the Math and
* StrictMath versions of log10. The role of this test is to verify
* that the FDLIBM log10 algorithm is being used by running golden
* file tests on values that may vary from one conforming log10
* implementation to another.
*/
public class Log10Tests {
private Log10Tests(){}
static int testLog10Case(double input, double expected) {
return Tests.test("StrictMath.log10(double)", input,
StrictMath.log10(input), expected);
}
static int testLog10() {
int failures = 0;
double [][] testCases = {
{0x1.3fffffffffec1p-297, -0x1.653c6a27ae2f8p6},
{0x1.4p-297, -0x1.653c6a27ae2f7p6},
{0x1.3fffffffffbe1p-296, -0x1.640828f2a4382p6},
{0x1.4p-296, -0x1.640828f2a437dp6},
{0x1.3fffffffffd52p-295, -0x1.62d3e7bd9a406p6},
{0x1.4p-295, -0x1.62d3e7bd9a403p6},
{0x1.3fffffffffa72p-294, -0x1.619fa6889049p6},
{0x1.4p-294, -0x1.619fa68890489p6},
{0x1.3fffffffff9bbp-293, -0x1.606b655386518p6},
{0x1.4p-293, -0x1.606b65538650fp6},
{0x1.3fffffffffbe4p-292, -0x1.5f37241e7c59ap6},
{0x1.4p-292, -0x1.5f37241e7c595p6},
{0x1.3ffffffffff7ep-291, -0x1.5e02e2e97261cp6},
{0x1.4p-291, -0x1.5e02e2e97261bp6},
{0x1.3fffffffffc9ep-290, -0x1.5ccea1b4686a6p6},
{0x1.4p-290, -0x1.5ccea1b4686a1p6},
{0x1.3fffffffffec7p-289, -0x1.5b9a607f5e728p6},
{0x1.4p-289, -0x1.5b9a607f5e727p6},
{0x1.3fffffffffbe7p-288, -0x1.5a661f4a547b2p6},
{0x1.4p-288, -0x1.5a661f4a547adp6},
{0x1.3fffffffff907p-287, -0x1.5931de154a83cp6},
{0x1.4p-287, -0x1.5931de154a833p6},
{0x1.3fffffffffd59p-286, -0x1.57fd9ce0408bcp6},
{0x1.4p-286, -0x1.57fd9ce0408b9p6},
{0x1.3fffffffffecap-285, -0x1.56c95bab3694p6},
{0x1.4p-285, -0x1.56c95bab3693fp6},
{0x1.3fffffffffbeap-284, -0x1.55951a762c9cap6},
{0x1.4p-284, -0x1.55951a762c9c5p6},
{0x1.3ffffffffff84p-283, -0x1.5460d94122a4cp6},
{0x1.4p-283, -0x1.5460d94122a4bp6},
{0x1.3fffffffffca4p-282, -0x1.532c980c18ad6p6},
{0x1.4p-282, -0x1.532c980c18ad1p6},
{0x1.3fffffffff9c4p-281, -0x1.51f856d70eb6p6},
{0x1.4p-281, -0x1.51f856d70eb57p6},
{0x1.3fffffffffe16p-280, -0x1.50c415a204bep6},
{0x1.4p-280, -0x1.50c415a204bddp6},
{0x1.3fffffffffd5ep-279, -0x1.4f8fd46cfac66p6},
{0x1.4p-279, -0x1.4f8fd46cfac63p6},
{0x1.3fffffffffd5fp-278, -0x1.4e5b9337f0cecp6},
{0x1.4p-278, -0x1.4e5b9337f0ce9p6},
{0x1.3fffffffffedp-277, -0x1.4d275202e6d7p6},
{0x1.4p-277, -0x1.4d275202e6d6fp6},
{0x1.3fffffffffbfp-276, -0x1.4bf310cddcdfap6},
{0x1.4p-276, -0x1.4bf310cddcdf5p6},
{0x1.3ffffffffff8ap-275, -0x1.4abecf98d2e7bp6},
{0x1.4p-275, -0x1.4abecf98d2e7bp6},
{0x1.3fffffffffd62p-274, -0x1.498a8e63c8f04p6},
{0x1.4p-274, -0x1.498a8e63c8f01p6},
{0x1.3fffffffff9cap-273, -0x1.48564d2ebef9p6},
{0x1.4p-273, -0x1.48564d2ebef87p6},
{0x1.3fffffffff6eap-272, -0x1.47220bf9b501ap6},
{0x1.4p-272, -0x1.47220bf9b500dp6},
{0x1.3fffffffffb3cp-271, -0x1.45edcac4ab09ap6},
{0x1.4p-271, -0x1.45edcac4ab093p6},
{0x1.3fffffffffd65p-270, -0x1.44b9898fa111cp6},
{0x1.4p-270, -0x1.44b9898fa1119p6},
{0x1.3fffffffffa85p-269, -0x1.4385485a971a6p6},
{0x1.4p-269, -0x1.4385485a9719fp6},
{0x1.3ffffffffe2c7p-268, -0x1.425107258d24dp6},
{0x1.3fffffffffed7p-268, -0x1.425107258d226p6},
{0x1.4p-268, -0x1.425107258d225p6},
{0x1.3fffffffff916p-267, -0x1.411cc5f0832b4p6},
{0x1.4p-267, -0x1.411cc5f0832abp6},
{0x1.3fffffffffd68p-266, -0x1.3fe884bb79334p6},
{0x1.4p-266, -0x1.3fe884bb79331p6},
{0x1.3fffffffffe21p-265, -0x1.3eb443866f3b9p6},
{0x1.4p-265, -0x1.3eb443866f3b7p6},
{0x1.3fffffffffedap-264, -0x1.3d8002516543ep6},
{0x1.4p-264, -0x1.3d8002516543dp6},
{0x1.3fffffffffbfap-263, -0x1.3c4bc11c5b4c9p6},
{0x1.4p-263, -0x1.3c4bc11c5b4c3p6},
{0x1.3fffffffff862p-262, -0x1.3b177fe751554p6},
{0x1.4p-262, -0x1.3b177fe751549p6},
{0x1.3fffffffffa8bp-261, -0x1.39e33eb2475d6p6},
{0x1.4p-261, -0x1.39e33eb2475cfp6},
{0x1.3fffffffffeddp-260, -0x1.38aefd7d3d656p6},
{0x1.4p-260, -0x1.38aefd7d3d655p6},
{0x1.3fffffffffbfdp-259, -0x1.377abc48336ep6},
{0x1.4p-259, -0x1.377abc48336dbp6},
{0x1.3ffffffffff97p-258, -0x1.36467b1329762p6},
{0x1.4p-258, -0x1.36467b1329761p6},
{0x1.3fffffffffedfp-257, -0x1.351239de1f7e8p6},
{0x1.4p-257, -0x1.351239de1f7e7p6},
{0x1.3fffffffffeep-256, -0x1.33ddf8a91586ep6},
{0x1.4p-256, -0x1.33ddf8a91586dp6},
{0x1.3fffffffffcp-255, -0x1.32a9b7740b8f8p6},
{0x1.4p-255, -0x1.32a9b7740b8f3p6},
{0x1.3fffffffffd71p-254, -0x1.3175763f0197cp6},
{0x1.4p-254, -0x1.3175763f01979p6},
{0x1.3fffffffff588p-253, -0x1.30413509f7a0ep6},
{0x1.4p-253, -0x1.30413509f79ffp6},
{0x1.3fffffffff7b1p-252, -0x1.2f0cf3d4eda9p6},
{0x1.4p-252, -0x1.2f0cf3d4eda85p6},
{0x1.3fffffffffc03p-251, -0x1.2dd8b29fe3b1p6},
{0x1.4p-251, -0x1.2dd8b29fe3b0bp6},
{0x1.3fffffffff86bp-250, -0x1.2ca4716ad9b9cp6},
{0x1.4p-250, -0x1.2ca4716ad9b91p6},
{0x1.3fffffffffcbdp-249, -0x1.2b703035cfc1cp6},
{0x1.4p-249, -0x1.2b703035cfc17p6},
{0x1.3fffffffffee6p-248, -0x1.2a3bef00c5c9ep6},
{0x1.4p-248, -0x1.2a3bef00c5c9dp6},
{0x1.3fffffffffc06p-247, -0x1.2907adcbbbd28p6},
{0x1.4p-247, -0x1.2907adcbbbd23p6},
{0x1.3fffffffffd77p-246, -0x1.27d36c96b1dacp6},
{0x1.4p-246, -0x1.27d36c96b1da9p6},
{0x1.3fffffffffd78p-245, -0x1.269f2b61a7e32p6},
{0x1.4p-245, -0x1.269f2b61a7e2fp6},
{0x1.3ffffffffea0bp-244, -0x1.256aea2c9ded3p6},
{0x1.3fffffffffee9p-244, -0x1.256aea2c9deb6p6},
{0x1.4p-244, -0x1.256aea2c9deb5p6},
{0x1.3fffffffffe32p-243, -0x1.2436a8f793f3ep6},
{0x1.4p-243, -0x1.2436a8f793f3bp6},
{0x1.3ffffffffffa3p-242, -0x1.230267c289fc2p6},
{0x1.4p-242, -0x1.230267c289fc1p6},
{0x1.3fffffffff591p-241, -0x1.21ce268d80056p6},
{0x1.4p-241, -0x1.21ce268d80047p6},
{0x1.3fffffffff9e3p-240, -0x1.2099e558760d6p6},
{0x1.4p-240, -0x1.2099e558760cdp6},
{0x1.3fffffffffc0cp-239, -0x1.1f65a4236c158p6},
{0x1.4p-239, -0x1.1f65a4236c153p6},
{0x1.3fffffffffd7dp-238, -0x1.1e3162ee621dcp6},
{0x1.4p-238, -0x1.1e3162ee621d9p6},
{0x1.3fffffffffd7ep-237, -0x1.1cfd21b958262p6},
{0x1.4p-237, -0x1.1cfd21b95825fp6},
{0x1.3fffffffffeefp-236, -0x1.1bc8e0844e2e6p6},
{0x1.4p-236, -0x1.1bc8e0844e2e5p6},
{0x1.3fffffffffc0fp-235, -0x1.1a949f4f4437p6},
{0x1.4p-235, -0x1.1a949f4f4436bp6},
{0x1.3ffffffffffa9p-234, -0x1.19605e1a3a3f1p6},
{0x1.4p-234, -0x1.19605e1a3a3f1p6},
{0x1.3ffffffffffaap-233, -0x1.182c1ce530478p6},
{0x1.4p-233, -0x1.182c1ce530477p6},
{0x1.3fffffffff2b7p-232, -0x1.16f7dbb02651p6},
{0x1.4p-232, -0x1.16f7dbb0264fdp6},
{0x1.3fffffffffef3p-231, -0x1.15c39a7b1c584p6},
{0x1.4p-231, -0x1.15c39a7b1c583p6},
{0x1.3fffffffff932p-230, -0x1.148f594612612p6},
{0x1.4p-230, -0x1.148f594612609p6},
{0x1.3fffffffffd84p-229, -0x1.135b181108692p6},
{0x1.4p-229, -0x1.135b18110868fp6},
{0x1.3fffffffffaa4p-228, -0x1.1226d6dbfe71cp6},
{0x1.4p-228, -0x1.1226d6dbfe715p6},
{0x1.3fffffffffef6p-227, -0x1.10f295a6f479cp6},
{0x1.4p-227, -0x1.10f295a6f479bp6},
{0x1.3fffffffffd86p-226, -0x1.0fbe5471ea824p6},
{0x1.4p-226, -0x1.0fbe5471ea821p6},
{0x1.3fffffffffd87p-225, -0x1.0e8a133ce08aap6},
{0x1.4p-225, -0x1.0e8a133ce08a7p6},
{0x1.3fffffffffef8p-224, -0x1.0d55d207d692ep6},
{0x1.4p-224, -0x1.0d55d207d692dp6},
{0x1.3fffffffffef9p-223, -0x1.0c2190d2cc9b4p6},
{0x1.4p-223, -0x1.0c2190d2cc9b3p6},
{0x1.3fffffffff42fp-222, -0x1.0aed4f9dc2a4ap6},
{0x1.4p-222, -0x1.0aed4f9dc2a39p6},
{0x1.3fffffffff658p-221, -0x1.09b90e68b8accp6},
{0x1.4p-221, -0x1.09b90e68b8abfp6},
{0x1.3fffffffffaaap-220, -0x1.0884cd33aeb4cp6},
{0x1.4p-220, -0x1.0884cd33aeb45p6},
{0x1.3fffffffffefcp-219, -0x1.07508bfea4bccp6},
{0x1.4p-219, -0x1.07508bfea4bcbp6},
{0x1.3fffffffffc1cp-218, -0x1.061c4ac99ac56p6},
{0x1.4p-218, -0x1.061c4ac99ac51p6},
{0x1.3fffffffffd8dp-217, -0x1.04e8099490cdap6},
{0x1.4p-217, -0x1.04e8099490cd7p6},
{0x1.3fffffffffaadp-216, -0x1.03b3c85f86d65p6},
{0x1.3fffffffffefep-216, -0x1.03b3c85f86d5ep6},
{0x1.4p-216, -0x1.03b3c85f86d5dp6},
{0x1.3ffffffffdbbdp-215, -0x1.027f872a7ce16p6},
{0x1.3fffffffffeffp-215, -0x1.027f872a7cde4p6},
{0x1.4p-215, -0x1.027f872a7cde3p6},
{0x1.3fffffffffc1fp-214, -0x1.014b45f572e6ep6},
{0x1.4p-214, -0x1.014b45f572e69p6},
{0x1.3ffffffffffb9p-213, -0x1.001704c068efp6},
{0x1.4p-213, -0x1.001704c068eefp6},
{0x1.3fffffffffdbfp-212, -0x1.fdc58716bdefp5},
{0x1.4p-212, -0x1.fdc58716bdeeap5},
{0x1.3ffffffffff3p-211, -0x1.fb5d04aca9ff8p5},
{0x1.4p-211, -0x1.fb5d04aca9ff6p5},
{0x1.3ffffffffffe9p-210, -0x1.f8f4824296102p5},
{0x1.4p-210, -0x1.f8f4824296102p5},
{0x1.3fffffffffd09p-209, -0x1.f68bffd882216p5},
{0x1.4p-209, -0x1.f68bffd88220ep5},
{0x1.3fffffffffdc2p-208, -0x1.f4237d6e6e32p5},
{0x1.4p-208, -0x1.f4237d6e6e31ap5},
{0x1.3fffffffff23fp-207, -0x1.f1bafb045a44cp5},
{0x1.3fffffffffe7bp-207, -0x1.f1bafb045a42ap5},
{0x1.4p-207, -0x1.f1bafb045a426p5},
{0x1.3ffffffffffecp-206, -0x1.ef52789a46532p5},
{0x1.4p-206, -0x1.ef52789a46532p5},
{0x1.3fffffffffdc4p-205, -0x1.ece9f63032644p5},
{0x1.4p-205, -0x1.ece9f6303263ep5},
{0x1.3ffffffffe211p-204, -0x1.ea8173c61e79ep5},
{0x1.3ffffffffff35p-204, -0x1.ea8173c61e74cp5},
{0x1.4p-204, -0x1.ea8173c61e74ap5},
{0x1.3ffffffffec25p-203, -0x1.e818f15c0a88ep5},
{0x1.3fffffffffe7ep-203, -0x1.e818f15c0a85ap5},
{0x1.4p-203, -0x1.e818f15c0a856p5},
{0x1.3ffffffffdcadp-202, -0x1.e5b06ef1f69c5p5},
{0x1.3fffffffffedbp-202, -0x1.e5b06ef1f6966p5},
{0x1.4p-202, -0x1.e5b06ef1f6962p5},
{0x1.3fffffffffd0fp-201, -0x1.e347ec87e2a76p5},
{0x1.4p-201, -0x1.e347ec87e2a6ep5},
{0x1.3fffffffffe8p-200, -0x1.e0df6a1dceb7ep5},
{0x1.4p-200, -0x1.e0df6a1dceb7ap5},
{0x1.3ffffffffff39p-199, -0x1.de76e7b3bac88p5},
{0x1.4p-199, -0x1.de76e7b3bac86p5},
{0x1.3fffffffffff2p-198, -0x1.dc0e6549a6d92p5},
{0x1.4p-198, -0x1.dc0e6549a6d92p5},
{0x1.3ffffffffff97p-197, -0x1.d9a5e2df92eap5},
{0x1.4p-197, -0x1.d9a5e2df92e9ep5},
{0x1.3fffffffffdcbp-196, -0x1.d73d60757efbp5},
{0x1.4p-196, -0x1.d73d60757efaap5},
{0x1.3ffffffffff3cp-195, -0x1.d4d4de0b6b0b8p5},
{0x1.4p-195, -0x1.d4d4de0b6b0b6p5},
{0x1.3fffffffffee1p-194, -0x1.d26c5ba1571c6p5},
{0x1.4p-194, -0x1.d26c5ba1571c2p5},
{0x1.3ffffffffff9ap-193, -0x1.d003d937432dp5},
{0x1.4p-193, -0x1.d003d937432cep5},
{0x1.3fffffffffdcep-192, -0x1.cd9b56cd2f3ep5},
{0x1.4p-192, -0x1.cd9b56cd2f3dap5},
{0x1.3fffffffffe87p-191, -0x1.cb32d4631b4eap5},
{0x1.4p-191, -0x1.cb32d4631b4e6p5},
{0x1.3fffffffffff8p-190, -0x1.c8ca51f9075f2p5},
{0x1.4p-190, -0x1.c8ca51f9075f2p5},
{0x1.3fffffffffff9p-189, -0x1.c661cf8ef36fep5},
{0x1.4p-189, -0x1.c661cf8ef36fep5},
{0x1.3fffffffffdd1p-188, -0x1.c3f94d24df81p5},
{0x1.4p-188, -0x1.c3f94d24df80ap5},
{0x1.3fffffffffe8ap-187, -0x1.c190cabacb91ap5},
{0x1.4p-187, -0x1.c190cabacb916p5},
{0x1.3ffffffffff43p-186, -0x1.bf284850b7a24p5},
{0x1.4p-186, -0x1.bf284850b7a22p5},
{0x1.3fffffffffffcp-185, -0x1.bcbfc5e6a3b2ep5},
{0x1.4p-185, -0x1.bcbfc5e6a3b2ep5},
{0x1.3ffffffffffa1p-184, -0x1.ba57437c8fc3cp5},
{0x1.4p-184, -0x1.ba57437c8fc3ap5},
{0x1.3fffffffffd79p-183, -0x1.b7eec1127bd4ep5},
{0x1.4p-183, -0x1.b7eec1127bd46p5},
{0x1.3fffffffffe32p-182, -0x1.b5863ea867e58p5},
{0x1.4p-182, -0x1.b5863ea867e52p5},
{0x1.3ffffffffe4a7p-181, -0x1.b31dbc3e53faap5},
{0x1.3ffffffffffffp-181, -0x1.b31dbc3e53f5ep5},
{0x1.4p-181, -0x1.b31dbc3e53f5ep5},
{0x1.3fffffffffdd7p-180, -0x1.b0b539d44007p5},
{0x1.4p-180, -0x1.b0b539d44006ap5},
{0x1.3fffffffffa9bp-179, -0x1.ae4cb76a2c185p5},
{0x1.3fffffffffe9p-179, -0x1.ae4cb76a2c17ap5},
{0x1.4p-179, -0x1.ae4cb76a2c177p5},
{0x1.3ffffffffe3f1p-178, -0x1.abe43500182d1p5},
{0x1.3ffffffffff49p-178, -0x1.abe4350018284p5},
{0x1.4p-178, -0x1.abe4350018283p5},
{0x1.3fffffffffc69p-177, -0x1.a97bb29604398p5},
{0x1.4p-177, -0x1.a97bb2960438fp5},
{0x1.3fffffffffddap-176, -0x1.a713302bf04ap5},
{0x1.4p-176, -0x1.a713302bf049bp5},
{0x1.3fffffffffe93p-175, -0x1.a4aaadc1dc5aap5},
{0x1.4p-175, -0x1.a4aaadc1dc5a7p5},
{0x1.3fffffffff481p-174, -0x1.a2422b57c86d3p5},
{0x1.3fffffffffe38p-174, -0x1.a2422b57c86b8p5},
{0x1.4p-174, -0x1.a2422b57c86b3p5},
{0x1.3fffffffffef1p-173, -0x1.9fd9a8edb47c2p5},
{0x1.4p-173, -0x1.9fd9a8edb47bfp5},
{0x1.3ffffffffffaap-172, -0x1.9d712683a08ccp5},
{0x1.4p-172, -0x1.9d712683a08cbp5},
{0x1.3fffffffffddep-171, -0x1.9b08a4198c9dcp5},
{0x1.4p-171, -0x1.9b08a4198c9d7p5},
{0x1.3ffffffffff4fp-170, -0x1.98a021af78ae4p5},
{0x1.4p-170, -0x1.98a021af78ae3p5},
{0x1.3fffffffffd27p-169, -0x1.96379f4564bf6p5},
{0x1.4p-169, -0x1.96379f4564befp5},
{0x1.3fffffffffdep-168, -0x1.93cf1cdb50dp5},
{0x1.4p-168, -0x1.93cf1cdb50cfbp5},
{0x1.3fffffffffe99p-167, -0x1.91669a713ce0ap5},
{0x1.4p-167, -0x1.91669a713ce07p5},
{0x1.3ffffffffff52p-166, -0x1.8efe180728f14p5},
{0x1.4p-166, -0x1.8efe180728f13p5},
{0x1.3fffffffffc72p-165, -0x1.8c95959d15028p5},
{0x1.4p-165, -0x1.8c95959d1501fp5},
{0x1.3ffffffffffbp-164, -0x1.8a2d13330112cp5},
{0x1.4p-164, -0x1.8a2d13330112bp5},
{0x1.3fffffffffd88p-163, -0x1.87c490c8ed23ep5},
{0x1.4p-163, -0x1.87c490c8ed237p5},
{0x1.3fffffffffe9dp-162, -0x1.855c0e5ed9346p5},
{0x1.4p-162, -0x1.855c0e5ed9343p5},
{0x1.3fffffffffefap-161, -0x1.82f38bf4c5452p5},
{0x1.4p-161, -0x1.82f38bf4c544fp5},
{0x1.3fffffffffd2ep-160, -0x1.808b098ab1562p5},
{0x1.4p-160, -0x1.808b098ab155bp5},
{0x1.3fffffffffe9fp-159, -0x1.7e2287209d66ap5},
{0x1.4p-159, -0x1.7e2287209d667p5},
{0x1.3ffffffffff58p-158, -0x1.7bba04b689774p5},
{0x1.4p-158, -0x1.7bba04b689773p5},
{0x1.3fffffffff099p-157, -0x1.7951824c758aap5},
{0x1.3ffffffffff59p-157, -0x1.7951824c7588p5},
{0x1.4p-157, -0x1.7951824c7587fp5},
{0x1.3fffffffffd31p-156, -0x1.76e8ffe261992p5},
{0x1.4p-156, -0x1.76e8ffe26198bp5},
{0x1.3fffffffffdeap-155, -0x1.74807d784da9cp5},
{0x1.4p-155, -0x1.74807d784da97p5},
{0x1.3fffffffffea3p-154, -0x1.7217fb0e39ba6p5},
{0x1.4p-154, -0x1.7217fb0e39ba3p5},
{0x1.3fffffffffc7bp-153, -0x1.6faf78a425cb8p5},
{0x1.3ffffffffff5cp-153, -0x1.6faf78a425cbp5},
{0x1.4p-153, -0x1.6faf78a425cafp5},
{0x1.3ffffffffffb9p-152, -0x1.6d46f63a11dbcp5},
{0x1.4p-152, -0x1.6d46f63a11dbbp5},
{0x1.3fffffffffa54p-151, -0x1.6ade73cffded6p5},
{0x1.4p-151, -0x1.6ade73cffdec7p5},
{0x1.3fffffffffbc5p-150, -0x1.6875f165e9fdfp5},
{0x1.3fffffffffea6p-150, -0x1.6875f165e9fd6p5},
{0x1.4p-150, -0x1.6875f165e9fd3p5},
{0x1.3ffffffffff5fp-149, -0x1.660d6efbd60ep5},
{0x1.4p-149, -0x1.660d6efbd60dfp5},
{0x1.3fffffffffdefp-148, -0x1.63a4ec91c21fp5},
{0x1.4p-148, -0x1.63a4ec91c21ebp5},
{0x1.3fffffffffea8p-147, -0x1.613c6a27ae2fap5},
{0x1.4p-147, -0x1.613c6a27ae2f7p5},
{0x1.3ffffffffff61p-146, -0x1.5ed3e7bd9a404p5},
{0x1.4p-146, -0x1.5ed3e7bd9a403p5},
{0x1.3ffffffffff62p-145, -0x1.5c6b65538651p5},
{0x1.4p-145, -0x1.5c6b65538650fp5},
{0x1.3ffffffffffbfp-144, -0x1.5a02e2e97261cp5},
{0x1.4p-144, -0x1.5a02e2e97261bp5},
{0x1.3fffffffffcdfp-143, -0x1.579a607f5e73p5},
{0x1.4p-143, -0x1.579a607f5e727p5},
{0x1.3fffffffffd98p-142, -0x1.5531de154a83ap5},
{0x1.4p-142, -0x1.5531de154a833p5},
{0x1.3fffffffffe51p-141, -0x1.52c95bab36944p5},
{0x1.4p-141, -0x1.52c95bab3693fp5},
{0x1.3ffffffffffc2p-140, -0x1.5060d94122a4cp5},
{0x1.4p-140, -0x1.5060d94122a4bp5},
{0x1.3fffffffffdf6p-139, -0x1.4df856d70eb5cp5},
{0x1.4p-139, -0x1.4df856d70eb57p5},
{0x1.3fffffffffeafp-138, -0x1.4b8fd46cfac66p5},
{0x1.4p-138, -0x1.4b8fd46cfac63p5},
{0x1.3ffffffffff68p-137, -0x1.49275202e6d7p5},
{0x1.4p-137, -0x1.49275202e6d6fp5},
{0x1.3ffffffffffc5p-136, -0x1.46becf98d2e7bp5},
{0x1.4p-136, -0x1.46becf98d2e7bp5},
{0x1.3fffffffffdf9p-135, -0x1.44564d2ebef8cp5},
{0x1.4p-135, -0x1.44564d2ebef87p5},
{0x1.3fffffffffeb2p-134, -0x1.41edcac4ab096p5},
{0x1.4p-134, -0x1.41edcac4ab093p5},
{0x1.3ffffffffff6bp-133, -0x1.3f85485a971ap5},
{0x1.4p-133, -0x1.3f85485a9719fp5},
{0x1.3ffffffffe699p-132, -0x1.3d1cc5f0832f2p5},
{0x1.3ffffffffff1p-132, -0x1.3d1cc5f0832aep5},
{0x1.4p-132, -0x1.3d1cc5f0832abp5},
{0x1.3ffffffffffc9p-131, -0x1.3ab443866f3b8p5},
{0x1.4p-131, -0x1.3ab443866f3b7p5},
{0x1.3fffffffffda1p-130, -0x1.384bc11c5b4cap5},
{0x1.4p-130, -0x1.384bc11c5b4c3p5},
{0x1.3ffffffffed15p-129, -0x1.35e33eb247604p5},
{0x1.3ffffffffff6ep-129, -0x1.35e33eb2475dp5},
{0x1.4p-129, -0x1.35e33eb2475cfp5},
{0x1.3ffffffffdd9dp-128, -0x1.337abc483373bp5},
{0x1.3fffffffffd46p-128, -0x1.337abc48336e2p5},
{0x1.4p-128, -0x1.337abc48336dbp5},
{0x1.3fffffffffdffp-127, -0x1.311239de1f7ecp5},
{0x1.4p-127, -0x1.311239de1f7e7p5},
{0x1.3fffffffff391p-126, -0x1.2ea9b7740b916p5},
{0x1.3ffffffffff7p-126, -0x1.2ea9b7740b8f4p5},
{0x1.4p-126, -0x1.2ea9b7740b8f3p5},
{0x1.3ffffffffff71p-125, -0x1.2c413509f7ap5},
{0x1.4p-125, -0x1.2c413509f79ffp5},
{0x1.3fffffffffc91p-124, -0x1.29d8b29fe3b14p5},
{0x1.4p-124, -0x1.29d8b29fe3b0bp5},
{0x1.3fffffffffd4ap-123, -0x1.27703035cfc1ep5},
{0x1.4p-123, -0x1.27703035cfc17p5},
{0x1.3fffffffffe03p-122, -0x1.2507adcbbbd28p5},
{0x1.4p-122, -0x1.2507adcbbbd23p5},
{0x1.3fffffffffebcp-121, -0x1.229f2b61a7e32p5},
{0x1.4p-121, -0x1.229f2b61a7e2fp5},
{0x1.3ffffffffff19p-120, -0x1.2036a8f793f3ep5},
{0x1.4p-120, -0x1.2036a8f793f3bp5},
{0x1.3fffffffffd4dp-119, -0x1.1dce268d8004ep5},
{0x1.4p-119, -0x1.1dce268d80047p5},
{0x1.3fffffffffebep-118, -0x1.1b65a4236c156p5},
{0x1.4p-118, -0x1.1b65a4236c153p5},
{0x1.3ffffffffff77p-117, -0x1.18fd21b95826p5},
{0x1.4p-117, -0x1.18fd21b95825fp5},
{0x1.3ffffffffffd4p-116, -0x1.16949f4f4436bp5},
{0x1.4p-116, -0x1.16949f4f4436bp5},
{0x1.3fffffffffe08p-115, -0x1.142c1ce53047cp5},
{0x1.4p-115, -0x1.142c1ce530477p5},
{0x1.3fffffffffe09p-114, -0x1.11c39a7b1c588p5},
{0x1.4p-114, -0x1.11c39a7b1c583p5},
{0x1.3fffffffffec2p-113, -0x1.0f5b181108692p5},
{0x1.4p-113, -0x1.0f5b18110868fp5},
{0x1.3ffffffffff7bp-112, -0x1.0cf295a6f479cp5},
{0x1.4p-112, -0x1.0cf295a6f479bp5},
{0x1.3ffffffffffd8p-111, -0x1.0a8a133ce08a8p5},
{0x1.4p-111, -0x1.0a8a133ce08a7p5},
{0x1.3fffffffffa73p-110, -0x1.082190d2cc9c2p5},
{0x1.4p-110, -0x1.082190d2cc9b3p5},
{0x1.3fffffffffec5p-109, -0x1.05b90e68b8ac2p5},
{0x1.4p-109, -0x1.05b90e68b8abfp5},
{0x1.3ffffffffedddp-108, -0x1.03508bfea4bfep5},
{0x1.3ffffffffff7ep-108, -0x1.03508bfea4bccp5},
{0x1.4p-108, -0x1.03508bfea4bcbp5},
{0x1.3ffffffffde65p-107, -0x1.00e8099490d35p5},
{0x1.3fffffffffe0ep-107, -0x1.00e8099490cdcp5},
{0x1.4p-107, -0x1.00e8099490cd7p5},
{0x1.3ffffffffed3dp-106, -0x1.fcff0e54f9c2fp4},
{0x1.3fffffffffe82p-106, -0x1.fcff0e54f9bcep4},
{0x1.4p-106, -0x1.fcff0e54f9bc6p4},
{0x1.3fffffffffff3p-105, -0x1.f82e0980d1ddep4},
{0x1.4p-105, -0x1.f82e0980d1ddep4},
{0x1.3ffffffffff98p-104, -0x1.f35d04aca9ff8p4},
{0x1.4p-104, -0x1.f35d04aca9ff6p4},
{0x1.3ffffffffe3b7p-103, -0x1.ee8bffd8822abp4},
{0x1.3ffffffffffc7p-103, -0x1.ee8bffd88221p4},
{0x1.4p-103, -0x1.ee8bffd88220ep4},
{0x1.3fffffffffdcdp-102, -0x1.e9bafb045a432p4},
{0x1.4p-102, -0x1.e9bafb045a426p4},
{0x1.3ffffffffff3ep-101, -0x1.e4e9f63032642p4},
{0x1.4p-101, -0x1.e4e9f6303263ep4},
{0x1.3ffffffffe301p-100, -0x1.e018f15c0a8f8p4},
{0x1.3fffffffffff7p-100, -0x1.e018f15c0a856p4},
{0x1.4p-100, -0x1.e018f15c0a856p4},
{0x1.3fffffffffd73p-99, -0x1.db47ec87e2a7cp4},
{0x1.4p-99, -0x1.db47ec87e2a6ep4},
{0x1.3ffffffffdd9dp-98, -0x1.d676e7b3bad46p4},
{0x1.3fffffffffee4p-98, -0x1.d676e7b3bac8cp4},
{0x1.4p-98, -0x1.d676e7b3bac86p4},
{0x1.3ffffffffff9dp-97, -0x1.d1a5e2df92eap4},
{0x1.4p-97, -0x1.d1a5e2df92e9ep4},
{0x1.3fffffffffffap-96, -0x1.ccd4de0b6b0b6p4},
{0x1.4p-96, -0x1.ccd4de0b6b0b6p4},
{0x1.3ffffffffffcdp-95, -0x1.c803d937432dp4},
{0x1.4p-95, -0x1.c803d937432cep4},
{0x1.3ffffffffffcep-94, -0x1.c332d4631b4e8p4},
{0x1.4p-94, -0x1.c332d4631b4e6p4},
{0x1.3fffffffffe8cp-93, -0x1.be61cf8ef3706p4},
{0x1.4p-93, -0x1.be61cf8ef36fep4},
{0x1.3fffffffff983p-92, -0x1.b990cabacb93ap4},
{0x1.3ffffffffff45p-92, -0x1.b990cabacb91ap4},
{0x1.4p-92, -0x1.b990cabacb916p4},
{0x1.3fffffffffffep-91, -0x1.b4bfc5e6a3b2ep4},
{0x1.4p-91, -0x1.b4bfc5e6a3b2ep4},
{0x1.3fffffffffdd6p-90, -0x1.afeec1127bd52p4},
{0x1.4p-90, -0x1.afeec1127bd46p4},
{0x1.3fffffffffeebp-89, -0x1.ab1dbc3e53f64p4},
{0x1.4p-89, -0x1.ab1dbc3e53f5ep4},
{0x1.3ffffffffffa4p-88, -0x1.a64cb76a2c178p4},
{0x1.4p-88, -0x1.a64cb76a2c177p4},
{0x1.3fffffffffa9bp-87, -0x1.a17bb296043acp4},
{0x1.3fffffffffd7cp-87, -0x1.a17bb2960439cp4},
{0x1.4p-87, -0x1.a17bb2960438fp4},
{0x1.3fffffffffe91p-86, -0x1.9caaadc1dc5aep4},
{0x1.3ffffffffffc5p-86, -0x1.9caaadc1dc5a8p4},
{0x1.3fffffffffe36p-85, -0x1.97d9a8edb47c8p4},
{0x1.3ffffffffffa7p-84, -0x1.9308a4198c9d8p4},
{0x1.3ffffffffff7ap-83, -0x1.8e379f4564bf2p4},
{0x1.3ffffffffffd7p-82, -0x1.89669a713ce08p4},
{0x1.3fffffffffe95p-81, -0x1.8495959d15026p4},
{0x1.3ffffffffff4ep-80, -0x1.7fc490c8ed23ap4},
{0x1.3ffffffffeafbp-79, -0x1.7af38bf4c54c3p4},
{0x1.3ffffffffffd9p-79, -0x1.7af38bf4c544fp4},
{0x1.3fffffffffe3bp-78, -0x1.762287209d67p4},
{0x1.3ffffffffde65p-77, -0x1.7151824c7593ap4},
{0x1.3fffffffffef4p-77, -0x1.7151824c75884p4},
{0x1.3ffffffffffadp-76, -0x1.6c807d784da98p4},
{0x1.3fffffffffb8bp-75, -0x1.67af78a425cc7p4},
{0x1.3ffffffffffaep-75, -0x1.67af78a425cbp4},
{0x1.3ffffffffffddp-74, -0x1.62de73cffdec8p4},
{0x1.3fffffffffe3fp-73, -0x1.5e0d6efbd60e8p4},
{0x1.3ffffffffff54p-72, -0x1.593c6a27ae2fap4},
{0x1.3ffffffffffb1p-71, -0x1.546b65538651p4},
{0x1.3fffffffff571p-70, -0x1.4f9a607f5e762p4},
{0x1.3fffffffffde5p-70, -0x1.4f9a607f5e732p4},
{0x1.3fffffffffe9ep-69, -0x1.4ac95bab36946p4},
{0x1.3ffffffffffb3p-68, -0x1.45f856d70eb58p4},
{0x1.3ffffffffe1d7p-67, -0x1.41275202e6e16p4},
{0x1.3ffffffffffb4p-67, -0x1.41275202e6d7p4},
{0x1.3fffffffffe44p-66, -0x1.3c564d2ebef9p4},
{0x1.3fffffffffd5fp-65, -0x1.3785485a971aep4},
{0x1.3fffffffffaadp-64, -0x1.32b443866f3d5p4},
{0x1.3fffffffffefep-64, -0x1.32b443866f3bcp4},
{0x1.3ffffffffeb35p-63, -0x1.2de33eb247643p4},
{0x1.3ffffffffffb7p-63, -0x1.2de33eb2475dp4},
{0x1.3ffffffffffe6p-62, -0x1.291239de1f7e8p4},
{0x1.3fffffffffdecp-61, -0x1.24413509f7a0ap4},
{0x1.3ffffffffff5dp-60, -0x1.1f703035cfc1ap4},
{0x1.3ffffffffffbap-59, -0x1.1a9f2b61a7e3p4},
{0x1.3fffffffffd92p-58, -0x1.15ce268d80054p4},
{0x1.3ffffffffff03p-57, -0x1.10fd21b958264p4},
{0x1.3ffffffffe6e9p-56, -0x1.0c2c1ce530503p4},
{0x1.3ffffffffffbcp-56, -0x1.0c2c1ce530478p4},
{0x1.3ffffffffe2c7p-55, -0x1.075b181108731p4},
{0x1.3ffffffffff61p-55, -0x1.075b181108692p4},
{0x1.3ffffffffffecp-54, -0x1.028a133ce08a8p4},
{0x1.3fffffffff14fp-53, -0x1.fb721cd171621p3},
{0x1.3fffffffffff8p-53, -0x1.fb721cd17157ep3},
{0x1.3ffffffffdd9dp-52, -0x1.f1d0132921b2dp3},
{0x1.3ffffffffffe2p-52, -0x1.f1d01329219bp3},
{0x1.3ffffffffebebp-51, -0x1.e82e0980d1ebdp3},
{0x1.3fffffffffe2dp-51, -0x1.e82e0980d1df2p3},
{0x1.3ffffffffff7p-50, -0x1.de8bffd882214p3},
{0x1.3fffffffffaadp-49, -0x1.d4e9f6303267ap3},
{0x1.3ffffffffffcdp-49, -0x1.d4e9f6303264p3},
{0x1.3fffffffffd77p-48, -0x1.cb47ec87e2a8ap3},
{0x1.3fffffffffda5p-48, -0x1.cb47ec87e2a89p3},
{0x1.3ffffffffff16p-47, -0x1.c1a5e2df92ea8p3},
{0x1.3fffffffff983p-46, -0x1.b803d93743316p3},
{0x1.3ffffffffffcfp-46, -0x1.b803d937432dp3},
{0x1.3ffffffffffa2p-45, -0x1.ae61cf8ef3702p3},
{0x1.3fffffffffbc5p-44, -0x1.a4bfc5e6a3b5ep3},
{0x1.3ffffffffffffp-44, -0x1.a4bfc5e6a3b2ep3},
{0x1.3fffffffffdd7p-43, -0x1.9b1dbc3e53f76p3},
{0x1.3fffffffffebep-42, -0x1.917bb2960439cp3},
{0x1.3ffffffffe3f1p-41, -0x1.87d9a8edb48f7p3},
{0x1.3ffffffffff77p-41, -0x1.87d9a8edb47c4p3},
{0x1.3fffffffff23fp-40, -0x1.7e379f4564c87p3},
{0x1.3ffffffffffbdp-40, -0x1.7e379f4564bf2p3},
{0x1.3fffffffffe36p-39, -0x1.7495959d15032p3},
{0x1.3ffffffffecdbp-38, -0x1.6af38bf4c5523p3},
{0x1.3ffffffffffa7p-38, -0x1.6af38bf4c5452p3},
{0x1.3ffffffffffd6p-37, -0x1.6151824c7588p3},
{0x1.3ffffffffffeep-36, -0x1.57af78a425cafp3},
{0x1.3ffffffffdcadp-35, -0x1.4e0d6efbd6268p3},
{0x1.3ffffffffffefp-35, -0x1.4e0d6efbd60ep3},
{0x1.3fffffffffe68p-34, -0x1.446b65538652p3},
{0x1.3ffffffffeafbp-33, -0x1.3ac95bab36a28p3},
{0x1.3ffffffffffd9p-33, -0x1.3ac95bab3694p3},
{0x1.3ffffffffffdap-32, -0x1.31275202e6d7p3},
{0x1.3fffffffffcb5p-31, -0x1.2785485a971c4p3},
{0x1.3ffffffffffc4p-31, -0x1.2785485a971a2p3},
{0x1.3fffffffffec7p-30, -0x1.1de33eb2475dcp3},
{0x1.3ffffffffffaep-29, -0x1.14413509f7a02p3},
{0x1.3ffffffffd9a3p-28, -0x1.0a9f2b61a7fd9p3},
{0x1.3ffffffffffddp-28, -0x1.0a9f2b61a7e3p3},
{0x1.3fffffffff32fp-27, -0x1.00fd21b9582edp3},
{0x1.3fffffffffe6dp-27, -0x1.00fd21b95827p3},
{0x1.3ffffffffffe4p-26, -0x1.eeb6302210d2p2},
{0x1.3ffffffffeb35p-25, -0x1.db721cd17174dp2},
{0x1.3fffffffffffcp-25, -0x1.db721cd17157ep2},
{0x1.3ffffffffde65p-24, -0x1.c82e0980d20cap2},
{0x1.3fffffffffeafp-24, -0x1.c82e0980d1dfcp2},
{0x1.3ffffffffed3dp-23, -0x1.b4e9f630327ep2},
{0x1.3ffffffffff7fp-23, -0x1.b4e9f6303264ap2},
{0x1.3ffffffffffdcp-22, -0x1.a1a5e2df92ea2p2},
{0x1.3ffffffffe91bp-21, -0x1.8e61cf8ef38fbp2},
{0x1.3ffffffffffffp-21, -0x1.8e61cf8ef36fep2},
{0x1.3fffffffffeb2p-20, -0x1.7b1dbc3e53f7bp2},
{0x1.3ffffffffe3b7p-19, -0x1.67d9a8edb4a33p2},
{0x1.3ffffffffff3dp-19, -0x1.67d9a8edb47dp2},
{0x1.3ffffffffe6e9p-18, -0x1.5495959d1524dp2},
{0x1.3fffffffffff6p-18, -0x1.5495959d1502p2},
{0x1.3ffffffffdb5bp-17, -0x1.4151824c75badp2},
{0x1.3ffffffffffebp-17, -0x1.4151824c7588p2},
{0x1.3ffffffffe301p-16, -0x1.2e0d6efbd6364p2},
{0x1.3ffffffffff11p-16, -0x1.2e0d6efbd60f3p2},
{0x1.3fffffffff14fp-15, -0x1.1ac95bab36a85p2},
{0x1.3ffffffffff57p-15, -0x1.1ac95bab3694ep2},
{0x1.3fffffffff481p-14, -0x1.0785485a9729fp2},
{0x1.3fffffffffff9p-14, -0x1.0785485a971ap2},
{0x1.3fffffffff571p-13, -0x1.e8826a13ef5d4p1},
{0x1.3fffffffffff1p-13, -0x1.e8826a13ef4p1},
{0x1.3fffffffffc7bp-12, -0x1.c1fa4372b055ap1},
{0x1.3ffffffffffcfp-12, -0x1.c1fa4372b04c6p1},
{0x1.3fffffffff189p-11, -0x1.9b721cd171802p1},
{0x1.3fffffffffffep-11, -0x1.9b721cd17157ep1},
{0x1.3ffffffffe211p-10, -0x1.74e9f63032b72p1},
{0x1.3fffffffffff3p-10, -0x1.74e9f6303264p1},
{0x1.3fffffffffbc5p-9, -0x1.4e61cf8ef37bbp1},
{0x1.3fffffffffff4p-9, -0x1.4e61cf8ef37p1},
{0x1.3fffffffff391p-8, -0x1.27d9a8edb49e8p1},
{0x1.3ffffffffffe9p-8, -0x1.27d9a8edb47c2p1},
{0x1.3fffffffffaadp-7, -0x1.0151824c7596cp1},
{0x1.3ffffffffffeap-7, -0x1.0151824c75882p1},
{0x1.3fffffffffc7bp-6, -0x1.b592b7566d3b6p0},
{0x1.3fffffffffff2p-6, -0x1.b592b7566d282p0},
{0x1.3fffffffffda5p-5, -0x1.68826a13ef4dp0},
{0x1.3fffffffffff6p-5, -0x1.68826a13ef402p0},
{0x1.3fffffffffb8bp-4, -0x1.1b721cd17170ap0},
{0x1.3ffffffffffffp-4, -0x1.1b721cd17157ep0},
{0x1.3fffffffffcb5p-3, -0x1.9cc39f1de7047p-1},
{0x1.3fffffffffff2p-3, -0x1.9cc39f1de6e06p-1},
{0x1.3fffffffffc7bp-2, -0x1.02a30498eb36fp-1},
{0x1.4p-2, -0x1.02a30498eb0fep-1},
{0x1.3fffffffffda5p-1, -0x1.a209a84fbd684p-3},
{0x1.3fffffffffffcp-1, -0x1.a209a84fbd002p-3},
{0x1.3fffffffffff3p0, 0x1.8cf18388647c5p-4},
{0x1.3fffffffffffdp0, 0x1.8cf18388647fbp-4},
{0x1.3ffffffffff7bp1, 0x1.977d95ec10b4ap-2},
{0x1.3fffffffffffcp1, 0x1.977d95ec10bfcp-2},
{0x1.3ffffffffff2bp2, 0x1.65df657b0426dp-1},
{0x1.3fffffffffff3p2, 0x1.65df657b042f8p-1},
{0x1.3fffffffffc83p4, 0x1.4d104d427dd4ap0},
{0x1.3fffffffffff1p4, 0x1.4d104d427de7ap0},
{0x1.4p4, 0x1.4d104d427de8p0},
{0x1.3ffffffffff2bp5, 0x1.9a209a84fbcb6p0},
{0x1.4p5, 0x1.9a209a84fbdp0},
{0x1.3fffffffffd23p6, 0x1.e730e7c779a81p0},
{0x1.3fffffffffffep6, 0x1.e730e7c779b7ep0},
{0x1.4p6, 0x1.e730e7c779b7fp0},
{0x1.3ffffffffece3p7, 0x1.1a209a84fb9aep1},
{0x1.4p7, 0x1.1a209a84fbdp1},
{0x1.3fffffffffeb3p8, 0x1.40a8c1263ac06p1},
{0x1.3ffffffffff71p8, 0x1.40a8c1263ac26p1},
{0x1.4p8, 0x1.40a8c1263ac3fp1},
{0x1.3fffffffffe3bp9, 0x1.6730e7c779b31p1},
{0x1.3fffffffffffcp9, 0x1.6730e7c779b7ep1},
{0x1.4p9, 0x1.6730e7c779b7fp1},
{0x1.3fffffffff657p10, 0x1.8db90e68b8912p1},
{0x1.3ffffffffff67p10, 0x1.8db90e68b8aa4p1},
{0x1.4p10, 0x1.8db90e68b8abfp1},
{0x1.3fffffffff8ffp11, 0x1.b4413509f78c8p1},
{0x1.3ffffffffffecp11, 0x1.b4413509f79fcp1},
{0x1.4p11, 0x1.b4413509f79ffp1},
{0x1.3fffffffffd23p12, 0x1.dac95bab368cp1},
{0x1.3ffffffffff5dp12, 0x1.dac95bab36922p1},
{0x1.4p12, 0x1.dac95bab3693fp1},
{0x1.3fffffffffe13p13, 0x1.00a8c1263ac15p2},
{0x1.3fffffffffee2p13, 0x1.00a8c1263ac26p2},
{0x1.4p13, 0x1.00a8c1263ac3fp2},
{0x1.3fffffffff193p14, 0x1.13ecd476da29fp2},
{0x1.3ffffffffffc9p14, 0x1.13ecd476da3dap2},
{0x1.4p14, 0x1.13ecd476da3dfp2},
{0x1.3fffffffff5b7p15, 0x1.2730e7c779a9bp2},
{0x1.3ffffffffff1dp15, 0x1.2730e7c779b6cp2},
{0x1.4p15, 0x1.2730e7c779b7fp2},
{0x1.3ffffffffec2fp16, 0x1.3a74fb1819167p2},
{0x1.3ffffffffffedp16, 0x1.3a74fb181931ep2},
{0x1.4p16, 0x1.3a74fb181931fp2},
{0x1.3fffffffffb07p17, 0x1.4db90e68b8a51p2},
{0x1.3fffffffffecep17, 0x1.4db90e68b8aa4p2},
{0x1.4p17, 0x1.4db90e68b8abfp2},
{0x1.3ffffffffff2bp18, 0x1.60fd21b95824dp2},
{0x1.3ffffffffffb5p18, 0x1.60fd21b958258p2},
{0x1.4p18, 0x1.60fd21b95825fp2},
{0x1.3ffffffffffe4p19, 0x1.74413509f79fcp2},
{0x1.4p19, 0x1.74413509f79ffp2},
{0x1.3fffffffff6cfp20, 0x1.8785485a970d3p2},
{0x1.3ffffffffffd9p20, 0x1.8785485a9719cp2},
{0x1.4p20, 0x1.8785485a9719fp2},
{0x1.3ffffffffed47p21, 0x1.9ac95bab3679fp2},
{0x1.3fffffffffebap21, 0x1.9ac95bab36922p2},
{0x1.4p21, 0x1.9ac95bab3693fp2},
{0x1.3fffffffff16bp22, 0x1.ae0d6efbd5f9bp2},
{0x1.3ffffffffff8ap22, 0x1.ae0d6efbd60d4p2},
{0x1.4p22, 0x1.ae0d6efbd60dfp2},
{0x1.3ffffffffe667p23, 0x1.c151824c75646p2},
{0x1.3fffffffffffep23, 0x1.c151824c7587ep2},
{0x1.4p23, 0x1.c151824c7587fp2},
{0x1.3fffffffffff3p24, 0x1.d495959d1501ep2},
{0x1.4p24, 0x1.d495959d1501fp2},
{0x1.3fffffffffadfp25, 0x1.e7d9a8edb474dp2},
{0x1.3fffffffffebdp25, 0x1.e7d9a8edb47a2p2},
{0x1.4p25, 0x1.e7d9a8edb47bfp2},
};
for (double[] testCase: testCases)
failures+=testLog10Case(testCase[0], testCase[1]);
return failures;
}
public static void main(String [] argv) {
int failures = 0;
failures += testLog10();
if (failures > 0) {
System.err.println("Testing log10 incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851638
* @summary Tests for StrictMath.log1p
* @author Joseph D. Darcy
*/
/**
* The tests in ../Math/Log1pTests.java test properties that should
* hold for any log1p implementation, including the FDLIBM-based one
* required for StrictMath.log1p. Therefore, the test cases in
* ../Math/Log1pTests.java are run against both the Math and
* StrictMath versions of log1p. The role of this test is to verify
* that the FDLIBM log1p algorithm is being used by running golden
* file tests on values that may vary from one conforming log1p
* implementation to another.
*/
public class Log1pTests {
private Log1pTests(){}
static int testLog1pCase(double input, double expected) {
return Tests.test("StrictMath.log1p(double)", input,
StrictMath.log1p(input), expected);
}
static int testLog1p() {
int failures = 0;
double [][] testCases = {
{0x1.fffffffffffffp-54, 0x1.fffffffffffffp-54},
{0x1.fffffffffcc48p-15, 0x1.fffc000aa74f3p-15},
{0x1.ffffffffff224p-14, 0x1.fff8002aa8ccfp-14},
{0x1.ffffffffff90cp-13, 0x1.fff000aaa23bdp-13},
{0x1.fffffffffffcep-4, 0x1.e27076e2af2bap-4},
{0x1.fffffffffffffp-2, 0x1.9f323ecbf984bp-2},
{0x1.ffffffffffffdp-1, 0x1.62e42fefa39eep-1},
{0x1.0p1, 0x1.193ea7aad030ap0},
{0x1.ffffffffffffbp1, 0x1.9c041f7ed8d31p0},
{0x1.fffffffffffffp2, 0x1.193ea7aad030ap1},
{0x1.fffffffffffe1p3, 0x1.6aa6bc1fa7f73p1},
{0x1.fffffffffffe1p4, 0x1.bf8d8f4d5b8cap1},
{0x1.ffffffffffff1p5, 0x1.0b29293942974p2},
{0x1.fffffffffff41p6, 0x1.37072a9b5b6b4p2},
{0x1.ffffffffffe65p7, 0x1.63241004e8fdep2},
{0x1.ffffffffffca1p8, 0x1.8f60adf041b73p2},
{0x1.fffffffffffffp9, 0x1.bbad39ebe1ccp2},
{0x1.fffffffffffffp10, 0x1.e801c1698ba43p2},
{0x1.ffffffffff2dep11, 0x1.0a2d23e3bb54bp3},
{0x1.ffffffffff18dp12, 0x1.205a66eeb4f81p3},
{0x1.ffffffffffff9p13, 0x1.368829f0af2dcp3},
{0x1.fffffffffbc1ep14, 0x1.4cb62cf069217p3},
{0x1.ffffffffffff5p16, 0x1.791282ee99d8ep3},
{0x1.fffffffffba46p17, 0x1.8f40bded96cd1p3},
{0x1.ffffffffffff7p18, 0x1.a56efcec920cbp3},
{0x1.ffffffffffff7p19, 0x1.bb9d3deb8c76ap3},
{0x1.ffffffffffff9p20, 0x1.d1cb7fea86bcap3},
{0x1.ffffffffffff7p24, 0x1.1542457b37d42p4},
{0x1.fffffffffffe7p29, 0x1.4cb5ecf0e964fp4},
{0x1.ffffffffffff9p30, 0x1.57cd0e704682p4},
{0x1.ffffffffffffbp34, 0x1.8429946e1cf5dp4},
{0x1.fffffffffffedp35, 0x1.8f40b5ed9912dp4},
{0x1.fffffffffffefp39, 0x1.bb9d3beb8c96ap4},
{0x1.fffffffffffe1p40, 0x1.c6b45d6b09abap4},
{0x1.fffffffffffe3p44, 0x1.f310e368fe17fp4},
{0x1.ffffffffffff5p45, 0x1.fe2804e87b34cp4},
{0x1.fffffffffffc5p66, 0x1.7386e22edf4a5p5},
{0x1.fffffffffff98p90, 0x1.f89c7428bca5fp5},
{0x1.a36e2eb1c317dp-14, 0x1.a368d0657ee51p-14},
{0x1.0624dd2f18d5cp-10, 0x1.060354f8c2226p-10},
{0x1.ffffffffffffdp-1, 0x1.62e42fefa39eep-1},
{0x1.8ffffffffffccp6, 0x1.275e2271bba28p2},
{0x1.f3fffffffff1p9, 0x1.ba2909ce4f846p2},
{0x1.387ffffffffa8p13, 0x1.26bbed6fbd838p3},
{0x1.869ffffffffe4p16, 0x1.7069f7a2d94f4p3},
{0x1.e847fffffff3ep19, 0x1.ba18abb1dedbcp3},
{0x1.312cfffffff23p23, 0x1.01e3b85ec299p4},
{0x1.7d783ffffff17p26, 0x1.26bb1bbe0482ap4},
{0x1.dcd64ffffffcep29, 0x1.4b927f3304b3ap4},
{0x1.2a05f1ffffa3p33, 0x1.7069e2aa317fep4},
{0x1.74876e7ffffbep36, 0x1.9541462195ffap4},
{0x1.d1a94a1fffddp39, 0x1.ba18a999000a6p4},
{0x1.2309ce53ffed2p43, 0x1.def00d106aa4ep4},
{0x1.6bcc41e8ffe73p46, 0x1.01e3b843eaa6cp5},
{0x1.c6bf52633fe7dp49, 0x1.144f69ff9ffbep5},
{0x1.1c37937e07fffp53, 0x1.26bb1bbb55515p5},
{0x1.6345785d89f12p56, 0x1.3926cd770aa62p5},
{0x1.bc16d674ec76ap59, 0x1.4b927f32bffb6p5},
{0x1.158e460913c51p63, 0x1.5dfe30ee75504p5},
{0x1.5af1d78b58badp66, 0x1.7069e2aa2aa58p5},
{0x1.b1ae4d6e2ecd4p69, 0x1.82d59465dffap5},
{0x1.0f0cf064dd066p73, 0x1.95414621954d6p5},
{0x1.52d02c7e14a9p76, 0x1.a7acf7dd4aa4cp5},
{0x1.a784379d99c19p79, 0x1.ba18a998fff98p5},
{0x1.08b2a2c27fb5p83, 0x1.cc845b54b54bap5},
{0x1.4adf4b7320322p86, 0x1.def00d106aa42p5},
{0x1.9d971e4fe7b91p89, 0x1.f15bbecc1ff6ap5},
{0x1.027e72f1f0ea3p93, 0x1.01e3b843eaa63p6},
{0x1.431e0fae6d44bp96, 0x1.0b199121c5512p6},
{0x1.93e5939a086bcp99, 0x1.144f69ff9ffb4p6},
{0x1.f8def8808ac86p102, 0x1.1d8542dd7aa65p6},
{0x1.3b8b5b5056dc7p106, 0x1.26bb1bbb55514p6},
{0x1.8a6e32246c76cp109, 0x1.2ff0f4992ffb8p6},
{0x1.ed09bead86a07p112, 0x1.3926cd770aa41p6},
{0x1.3426172c74d33p116, 0x1.425ca654e550ep6},
{0x1.812f9cf791f1ep119, 0x1.4b927f32bffb4p6},
{0x1.e17b8435758f2p122, 0x1.54c858109aa3ep6},
{0x1.2ced32a169cfap126, 0x1.5dfe30ee754fap6},
{0x1.78287f49c497cp129, 0x1.673409cc4ffbp6},
{0x1.d6329f1c3492ep132, 0x1.7069e2aa2aa3p6},
{0x1.25dfa371a14b8p136, 0x1.799fbb88054f2p6},
{0x1.6f578c4e09f0ap139, 0x1.82d59465dffa8p6},
{0x1.cb2d6f618c4b4p142, 0x1.8c0b6d43baa4cp6},
{0x1.1efc659cf77abp146, 0x1.95414621954eap6},
{0x1.66bb7f0435c5bp149, 0x1.9e771eff6ffa6p6},
{0x1.c06a5ec5428a4p152, 0x1.a7acf7dd4aa36p6},
{0x1.18427b3b49fc9p156, 0x1.b0e2d0bb254f6p6},
{0x1.5e531a0a1c729p159, 0x1.ba18a998fff9cp6},
{0x1.b5e7e08ca3686p162, 0x1.c34e8276daa4p6},
{0x1.11b0ec57e6492p166, 0x1.cc845b54b54f2p6},
{0x1.561d276ddfd7dp169, 0x1.d5ba34328ff9ap6},
{0x1.aba471495757bp172, 0x1.def00d106aa3p6},
{0x1.0b46c6cdd6a8ep176, 0x1.e825e5ee454ddp6},
{0x1.4e1878814c5f4p179, 0x1.f15bbecc1ff88p6},
{0x1.a19e96a19f65ap182, 0x1.fa9197a9faa2ep6},
{0x1.05031e2503cfcp186, 0x1.01e3b843eaa71p7},
{0x1.4643e5ae441d2p189, 0x1.067ea4b2d7fb6p7},
{0x1.97d4df19d5c5dp192, 0x1.0b199121c5516p7},
{0x1.fdca16e04ae24p195, 0x1.0fb47d90b2a65p7},
{0x1.3e9e4e4c2f2dap199, 0x1.144f69ff9ffc4p7},
{0x1.8e45e1df3ac31p202, 0x1.18ea566e8d514p7},
{0x1.f1d75a5709306p205, 0x1.1d8542dd7aa63p7},
{0x1.372698766608cp209, 0x1.22202f4c67fcp7},
{0x1.84f03e93fef5p212, 0x1.26bb1bbb55508p7},
{0x1.e62c4e38fdba1p215, 0x1.2b56082a42a4bp7},
{0x1.2fdbb0e39f6b8p219, 0x1.2ff0f4992ffb6p7},
{0x1.7bd29d1c875a2p222, 0x1.348be1081d50cp7},
{0x1.dac74463a76e9p225, 0x1.3926cd770aa42p7},
{0x1.28bc8abe48f57p229, 0x1.3dc1b9e5f7fap7},
{0x1.72ebad6ddc67ep232, 0x1.425ca654e550ep7},
{0x1.cfa698c952a3ap235, 0x1.46f792c3d2a53p7},
{0x1.21c81f7dd42b1p239, 0x1.4b927f32bffb6p7},
{0x1.6a3a275d4926bp242, 0x1.502d6ba1ad50ap7},
{0x1.c4c8b134970ddp245, 0x1.54c858109aa0ep7},
{0x1.61bcca711985dp252, 0x1.5dfe30ee75508p7},
{0x1.ba2bfd0d5fe2ap255, 0x1.62991d5d62a5cp7},
{0x1.59725db2728b7p262, 0x1.6bcef63b3d4fcp7},
{0x1.afcef51f0fa33p265, 0x1.7069e2aa2aa5ap7},
{0x1.0de1593368f8cp269, 0x1.7504cf1917f95p7},
{0x1.5159af804425ep272, 0x1.799fbb88055p7},
{0x1.a5b01b605409p275, 0x1.7e3aa7f6f2a3ep7},
{0x1.078e111c34e5bp279, 0x1.82d59465dff9fp7},
{0x1.497195634225fp282, 0x1.877080d4cd4f4p7},
{0x1.9bcdfabc13053p285, 0x1.8c0b6d43baa4ep7},
{0x1.0160bcb58c08cp289, 0x1.90a659b2a7fa7p7},
{0x1.41b8ebe2eec13p292, 0x1.95414621954f4p7},
{0x1.922726dbaa542p295, 0x1.99dc329082a46p7},
{0x1.f6b0f09295714p298, 0x1.9e771eff6ffa3p7},
{0x1.3a2e965b9d0b2p302, 0x1.a3120b6e5d4eep7},
{0x1.88ba3bf284dd1p305, 0x1.a7acf7dd4aa4ep7},
{0x1.32d17ed576f35p312, 0x1.b0e2d0bb254ep7},
{0x1.7f85de8ad56bep315, 0x1.b57dbd2a12a44p7},
{0x1.df67562d87c5cp318, 0x1.ba18a998fff65p7},
{0x1.2ba095dc76db7p322, 0x1.beb39607ed4fp7},
{0x1.7688bb5394bd3p325, 0x1.c34e8276daa48p7},
{0x1.d42aea2878b45p328, 0x1.c7e96ee5c7f87p7},
{0x1.249ad2594989p332, 0x1.cc845b54b54a6p7},
};
for (double[] testCase: testCases)
failures+=testLog1pCase(testCase[0], testCase[1]);
return failures;
}
public static void main(String [] argv) {
int failures = 0;
failures += testLog1p();
if (failures > 0) {
System.err.println("Testing log1p incurred "
+ failures + " failures.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
*
*
* Shared static test method for StrictMath tests.
*/
public class Tests {
private Tests(){}
static int test(String testName,
double input,
double result,
double expected) {
if (Double.compare(expected, result ) != 0) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input + "\t(" + Double.toHexString(input) + ")\n" +
"\texpected " + expected + "\t(" + Double.toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + Double.toHexString(result) + ").");
return 1;
}
else
return 0;
}
static int test(String testName, double input1, double input2,
double result, double expected) {
if (Double.compare(expected, result ) != 0) {
System.err.println("Failure for " + testName + ":\n" +
"\tFor input " + input1 + "\t(" + Double.toHexString(input1) + "), " +
+ input2 + "\t(" + Double.toHexString(input2) + ")\n" +
"\texpected " + expected + "\t(" + Double.toHexString(expected) + ")\n" +
"\tgot " + result + "\t(" + Double.toHexString(result) + ").");
return 1;
}
else
return 0;
}
}
/*
* Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4031762
* @summary Test the primitive wrappers static toString()
*/
import java.util.Random;
public class ToString {
private static Random generator = new Random();
public static void main(String args[]) throws Exception {
// boolean wrapper
boolean b = false;
Boolean B = new Boolean(b);
if (!B.toString().equals(Boolean.toString(b)))
throw new RuntimeException("Boolean wrapper toString() failure.");
b = true;
B = new Boolean(b);
if (!B.toString().equals(Boolean.toString(b)))
throw new RuntimeException("Boolean wrapper toString() failure.");
// char wrapper
for(int x=0; x<100; x++) {
char c = (char)generator.nextInt();
Character C = new Character(c);
if (!C.toString().equals(Character.toString(c)))
throw new RuntimeException("Character wrapper toString() failure.");
}
// byte wrapper
for(int x=0; x<100; x++) {
byte y = (byte)generator.nextInt();
Byte Y = new Byte(y);
if (!Y.toString().equals(Byte.toString(y)))
throw new RuntimeException("Byte wrapper toString() failure.");
}
// short wrapper
for(int x=0; x<100; x++) {
short s = (short)generator.nextInt();
Short S = new Short(s);
if (!S.toString().equals(Short.toString(s)))
throw new RuntimeException("Short wrapper toString() failure.");
}
// int wrapper
for(int x=0; x<100; x++) {
int i = generator.nextInt();
Integer I = new Integer(i);
if (!I.toString().equals(Integer.toString(i)))
throw new RuntimeException("Integer wrapper toString() failure.");
}
// long wrapper
for(int x=0; x<100; x++) {
long l = generator.nextLong();
Long L = new Long(l);
if (!L.toString().equals(Long.toString(l)))
throw new RuntimeException("Long wrapper toString() failure.");
}
// float wrapper
for(int x=0; x<100; x++) {
float f = generator.nextFloat();
Float F = new Float(f);
if (!F.toString().equals(Float.toString(f)))
throw new RuntimeException("Float wrapper toString() failure.");
}
// double wrapper
for(int x=0; x<100; x++) {
double d = generator.nextDouble();
Double D = new Double(d);
if (!D.toString().equals(Double.toString(d)))
throw new RuntimeException("Double wrapper toString() failure.");
}
}
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6179014
* @summary AnnotationTypeMismatchException.foundType method shouldn't loop.
* @author Scott Seligman
* @run main/timeout=30 FoundType
*/
import java.lang.annotation.*;
public class FoundType {
private static final String TYPE = "a.halting.Problem";
public static void main(String[] args) {
AnnotationTypeMismatchException ex =
new AnnotationTypeMismatchException(null, TYPE);
if (!TYPE.equals(ex.foundType()))
throw new Error();
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* Class to have a missing annotation applied for running MissingTest.
*/
@Missing
@Marker
public class A {
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* Class to have an indirectly missing annotation applied for for
* running MisssingTest.
*/
@MissingWrapper(@Missing)
@Marker
public class B {
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* Class to have a missing annotation applied for running MissingTest.
*/
public class C {
public void method1(@Missing @Marker Object param1) {
return;
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* Class to have a missing annotation applied for running MissingTest.
*/
public class D {
public void method1(@MissingWrapper(@Missing) @Marker Object param1) {
return;
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.*;
/**
* A marker annotation. Used so that at least one annotation will be
* present on the classes tested by MissingTest.
*/
@Retention(RUNTIME)
public @interface Marker {}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.*;
/**
* The class file for this annotation type is missing when MissingTest
* is run.
*/
@Retention(RUNTIME)
public @interface Missing {}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6322301
* @summary Verify when missing annotation classes cause exceptions
* @author Joseph D. Darcy
* @compile MissingTest.java A.java B.java C.java D.java Marker.java Missing.java MissingWrapper.java
* @clean Missing
* @run main MissingTest
*/
import java.lang.reflect.*;
/**
* This test verifies that a missing annotation class leads to the
* expected exceptional behavior; a missing directly applied
* annotation is currently ignored but a missing annotation value
* inside another annotation throws an exception.
*
* To be run as intended, the annotation type Missing should *not* be
* on the classpath when the test is run; with jtreg, it is deleted by
* the @clean directive.
*/
public class MissingTest {
/**
* For the annotated element argument, get all its annotations and
* see whether or not an exception is throw upon reading the
* annotations. Additionally, verify at least one annotation is
* present.
*/
private static void testAnnotation(AnnotatedElement element,
boolean exceptionExpected) {
java.lang.annotation.Annotation[] annotations;
try {
annotations = element.getAnnotations();
if (exceptionExpected) {
System.err.println("Error: Did not get an exception reading annotations on "
+ element);
System.err.println("Annotations found: "
+ java.util.Arrays.toString(annotations));
throw new RuntimeException();
}
if (annotations.length == 0) {
System.err.println("Error: no annotations found on " + element);
throw new RuntimeException();
}
} catch (Throwable t) {
if (!exceptionExpected) {
System.err.println("Error: Got an unexpected exception reading annotations on "
+ element);
throw new RuntimeException(t);
}
}
}
/**
* For the annotated element argument, get all its annotations and
* see whether or not an exception is throw upon reading the
* annotations. Additionally, verify at least one annotation is
* present.
*/
private static void testParameterAnnotation(Method m,
boolean exceptionExpected) {
java.lang.annotation.Annotation[][] annotationsArray;
try {
annotationsArray = m.getParameterAnnotations();
if (exceptionExpected) {
System.err.println("Error: Did not get an exception reading annotations on method"
+ m);
System.err.println("Annotations found: "
+ java.util.Arrays.toString(annotationsArray));
throw new RuntimeException();
}
if (annotationsArray.length == 0 ) {
System.err.println("Error: no parameters for " + m);
throw new RuntimeException();
} else {
java.lang.annotation.Annotation[] annotations = annotationsArray[0];
if (annotations.length == 0) {
System.err.println("Error: no annotations on " + m);
throw new RuntimeException();
}
}
} catch (Throwable t) {
if (!exceptionExpected) {
System.err.println("Error: Got an unexpected exception reading annotations on "
+ m);
throw new RuntimeException(t);
}
}
}
public static void main(String argv[]) throws Exception {
// Class A has a directly applied annotation whose class is
// missing.
testAnnotation(A.class, false);
// Class B has a directly applied annotation whose value
// includes to an annotation class that is missing.
testAnnotation(B.class, true);
// Class C has a directly applied parameter annotation whose
// class is missing.
testParameterAnnotation(C.class.getDeclaredMethod("method1", Object.class),
false);
// Class D has a directly applied parameter annotation whose value
// includes to an annotation class that is missing.
testParameterAnnotation(D.class.getDeclaredMethod("method1", Object.class),
true);
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.*;
/**
* Annotation wrapper around an annotation whose class will be missing
* when MissingTest is run.
*/
@Retention(RUNTIME)
public @interface MissingWrapper {
Missing value();
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.lang.annotation.Documented;
public class PackageMain {
public static void main(String[] args) throws Exception {
Class<?> c = Class.forName("foo.bar.Baz");
System.out.println("c=" + c);
System.out.println("cl=" + c.getClassLoader());
Package p = c.getPackage();
System.out.println("p=" + p);
Documented d = p.getAnnotation(Documented.class);
if (d == null) throw new Error();
}
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5037685
* @summary Under certain circumstances, recursive annotations disappeared
* @author Josh Bloch
*/
import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
@Rat public class RecursiveAnnotation {
public static void main(String[] args) {
if (!RecursiveAnnotation.class.isAnnotationPresent(Rat.class))
throw new RuntimeException("RecursiveAnnotation");
if (!Rat.class.isAnnotationPresent(Rat.class))
throw new RuntimeException("Rat");
}
}
@Retention(RUNTIME) @Rat @interface Rat { }
因为 它太大了无法显示 source diff 。你可以改为 查看blob
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
public
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
@interface A {
B b();
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
public @interface B {}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
public @A(b=@B()) class C {}
#!/bin/sh
# Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
if [ "${TESTSRC}" = "" ]
then
echo "TESTSRC not set. Test cannot execute. Failed."
exit 1
fi
echo "TESTSRC=${TESTSRC}"
if [ "${TESTJAVA}" = "" ]
then
echo "TESTJAVA not set. Test cannot execute. Failed."
exit 1
fi
echo "TESTJAVA=${TESTJAVA}"
if [ "${TESTCLASSES}" = "" ]
then
echo "TESTCLASSES not set. Test cannot execute. Failed."
exit 1
fi
echo "TESTCLASSES=${TESTCLASSES}"
echo "CLASSPATH=${CLASSPATH}"
# set platform-dependent variables
OS=`uname -s`
case "$OS" in
SunOS | Linux )
NULL=/dev/null
PS=":"
FS="/"
;;
Windows* )
NULL=NUL
PS=";"
FS="\\"
;;
* )
echo "Unrecognized system!"
exit 1;
;;
esac
mkdir -p classes
cp ${TESTSRC}${FS}*.java .
${TESTJAVA}${FS}bin${FS}javac -d classes A.java B.java C.java
${TESTJAVA}${FS}bin${FS}javac Main.java
${TESTJAVA}${FS}bin${FS}java Main
result=$?
if [ $result -eq 0 ]
then
echo "Passed 1 of 2"
else
echo "Failed 1 of 2"
exit $result
fi
${TESTJAVA}${FS}bin${FS}java Main foo
result=$?
if [ $result -eq 0 ]
then
echo "Passed 2 of 2"
else
echo "Failed 2 of 2"
fi
exit $result
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 5040740
* @summary annotations cause memory leak
* @author gafter
*
* @run shell LoaderLeak.sh
*/
import java.net.*;
import java.lang.ref.*;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws Exception {
for (int i=0; i<100; i++)
doTest(args.length != 0);
}
static void doTest(boolean readAnn) throws Exception {
// URL classes = new URL("file://" + System.getProperty("user.dir") + "/classes");
// URL[] path = { classes };
// URLClassLoader loader = new URLClassLoader(path);
ClassLoader loader = new SimpleClassLoader();
WeakReference<Class<?>> c = new WeakReference(loader.loadClass("C"));
if (c.get() == null) throw new AssertionError();
if (c.get().getClassLoader() != loader) throw new AssertionError();
if (readAnn) System.out.println(c.get().getAnnotations()[0]);
if (c.get() == null) throw new AssertionError();
System.gc();
System.gc();
if (c.get() == null) throw new AssertionError();
System.gc();
System.gc();
loader = null;
System.gc();
System.gc();
if (c.get() != null) throw new AssertionError();
}
}
class SimpleClassLoader extends ClassLoader {
private Hashtable classes = new Hashtable();
public SimpleClassLoader() {
}
private byte getClassImplFromDataBase(String className)[] {
byte result[];
try {
FileInputStream fi = new FileInputStream("classes/"+className+".class");
result = new byte[fi.available()];
fi.read(result);
return result;
} catch (Exception e) {
/*
* If we caught an exception, either the class wasnt found or it
* was unreadable by our process.
*/
return null;
}
}
public Class loadClass(String className) throws ClassNotFoundException {
return (loadClass(className, true));
}
public synchronized Class loadClass(String className, boolean resolveIt)
throws ClassNotFoundException {
Class result;
byte classData[];
/* Check our local cache of classes */
result = (Class)classes.get(className);
if (result != null) {
return result;
}
/* Check with the primordial class loader */
try {
result = super.findSystemClass(className);
return result;
} catch (ClassNotFoundException e) {
}
/* Try to load it from our repository */
classData = getClassImplFromDataBase(className);
if (classData == null) {
throw new ClassNotFoundException();
}
/* Define it (parse the class file) */
result = defineClass(classData, 0, classData.length);
if (result == null) {
throw new ClassFormatError();
}
if (resolveIt) {
resolveClass(result);
}
classes.put(className, result);
return result;
}
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4901290 5037531
* @summary Package annotations
* @author gafter
*
* @compile -source 1.5 package-info.java PackageMain.java
* @run main PackageMain
*/
@java.lang.annotation.Documented
package foo.bar;
class Baz {}
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6362557
* @summary Some tests of add(BigDecimal, mc)
* @author Joseph D. Darcy
*/
import java.math.*;
import static java.math.BigDecimal.*;
import java.util.Set;
import java.util.EnumSet;
public class AddTests {
private static Set<RoundingMode> nonExactRoundingModes =
EnumSet.complementOf(EnumSet.of(RoundingMode.UNNECESSARY));
/**
* Test for extreme value of scale and rounding precision that
* could cause integer overflow in right-shift-into-sticky-bit
* computations.
*/
private static int extremaTests() {
int failures = 0;
failures += addWithoutException(valueOf(1, -Integer.MAX_VALUE),
valueOf(2, Integer.MAX_VALUE), null);
failures += addWithoutException(valueOf(1, -Integer.MAX_VALUE),
valueOf(-2, Integer.MAX_VALUE), null);
return failures;
}
/**
* Print sum of b1 and b2; correct result will not throw an
* exception.
*/
private static int addWithoutException(BigDecimal b1, BigDecimal b2, MathContext mc) {
if (mc == null)
mc = new MathContext(2, RoundingMode.DOWN);
try {
BigDecimal sum = b1.add(b2, mc);
printAddition(b1, b2, sum.toString());
return 0;
} catch(ArithmeticException ae) {
printAddition(b1, b2, "Exception!");
return 1;
}
}
/**
* Test combinations of operands that may meet the condensation
* criteria when rounded to different precisions.
*/
private static int roundingGradationTests() {
int failures = 0;
failures += roundAway(new BigDecimal("1234e100"),
new BigDecimal( "1234e97"));
failures += roundAway(new BigDecimal("1234e100"),
new BigDecimal( "1234e96"));
failures += roundAway(new BigDecimal("1234e100"),
new BigDecimal( "1234e95"));
failures += roundAway(new BigDecimal("1234e100"),
new BigDecimal( "1234e94"));
failures += roundAway(new BigDecimal("1234e100"),
new BigDecimal( "1234e93"));
failures += roundAway(new BigDecimal("1234e100"),
new BigDecimal( "1234e92"));
failures += roundAway(new BigDecimal("1234e100"),
new BigDecimal("1234e50"));
failures += roundAway(new BigDecimal("1000e100"),
new BigDecimal( "1234e97"));
failures += roundAway(new BigDecimal("1000e100"),
new BigDecimal( "1234e96"));
failures += roundAway(new BigDecimal("1000e100"),
new BigDecimal( "1234e95"));
failures += roundAway(new BigDecimal("1000e100"),
new BigDecimal( "1234e94"));
failures += roundAway(new BigDecimal("1000e100"),
new BigDecimal( "1234e93"));
failures += roundAway(new BigDecimal("1000e100"),
new BigDecimal( "1234e92"));
failures += roundAway(new BigDecimal("1000e100"),
new BigDecimal("1234e50"));
failures += roundAway(new BigDecimal("1999e100"),
new BigDecimal( "1234e97"));
failures += roundAway(new BigDecimal("1999e100"),
new BigDecimal( "1234e96"));
failures += roundAway(new BigDecimal("1999e100"),
new BigDecimal( "1234e95"));
failures += roundAway(new BigDecimal("1999e100"),
new BigDecimal( "1234e94"));
failures += roundAway(new BigDecimal("1999e100"),
new BigDecimal( "1234e93"));
failures += roundAway(new BigDecimal("1999e100"),
new BigDecimal( "1234e92"));
failures += roundAway(new BigDecimal("1999e100"),
new BigDecimal("1234e50"));
failures += roundAway(new BigDecimal("9999e100"),
new BigDecimal( "1234e97"));
failures += roundAway(new BigDecimal("9999e100"),
new BigDecimal( "1234e96"));
failures += roundAway(new BigDecimal("9999e100"),
new BigDecimal( "1234e95"));
failures += roundAway(new BigDecimal("9999e100"),
new BigDecimal( "1234e94"));
failures += roundAway(new BigDecimal("9999e100"),
new BigDecimal( "1234e93"));
failures += roundAway(new BigDecimal("9999e100"),
new BigDecimal( "1234e92"));
failures += roundAway(new BigDecimal("9999e100"),
new BigDecimal("1234e50"));
return failures;
}
private static void printAddition(BigDecimal b1, BigDecimal b2, String s) {
System.out.println("" + b1+ "\t+\t" + b2 + "\t=\t" + s);
}
private static int roundAway(BigDecimal b1, BigDecimal b2) {
int failures = 0;
b1.precision();
b2.precision();
BigDecimal b1_negate = b1.negate();
BigDecimal b2_negate = b2.negate();
b1_negate.precision();
b2_negate.precision();
failures += roundAway1(b1, b2);
failures += roundAway1(b1, b2_negate);
failures += roundAway1(b1_negate, b2);
failures += roundAway1(b1_negate, b2_negate);
return failures;
}
private static int roundAway1(BigDecimal b1, BigDecimal b2) {
int failures = 0;
failures += roundAway0(b1, b2);
failures += roundAway0(b2, b1);
return failures;
}
/**
* Compare b1.add(b2, mc) with b1.add(b2).round(mc) for a variety
* of MathContexts.
*/
private static int roundAway0(BigDecimal b1, BigDecimal b2) {
int failures = 0;
BigDecimal exactSum = b1.add(b2);
for(int precision = 1 ; precision < exactSum.precision()+2; precision++) {
for(RoundingMode rm : nonExactRoundingModes) {
MathContext mc = new MathContext(precision, rm);
BigDecimal roundedExactSum = exactSum.round(mc);
try {
BigDecimal sum = b1.add(b2, mc);
if (!roundedExactSum.equals(sum) ) {
failures++;
System.out.println("Exact sum " + exactSum +
"\trounded by " + mc +
"\texpected: " + roundedExactSum + " got: ");
printAddition(b1, b2, sum.toString());
}
// else {
// System.out.print(mc + "\t");
// printAddition(b1, b2, sum.toString());
// }
} catch (ArithmeticException ae) {
printAddition(b1, b2, "Exception!");
failures++;
}
}
}
return failures;
}
/**
* Verify calling the precision method should not change the
* computed result.
*/
private static int precisionConsistencyTest() {
int failures = 0;
MathContext mc = new MathContext(1,RoundingMode.DOWN);
BigDecimal a = BigDecimal.valueOf(1999, -1); //value is equivalent to 19990
BigDecimal sum1 = a.add(BigDecimal.ONE, mc);
a.precision();
BigDecimal sum2 = a.add(BigDecimal.ONE, mc);
if (!sum1.equals(sum2)) {
failures ++;
System.out.println("Unequal sums after calling precision!");
System.out.print("Before:\t");
printAddition(a, BigDecimal.ONE, sum1.toString());
System.out.print("After:\t");
printAddition(a, BigDecimal.ONE, sum2.toString());
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += extremaTests();
failures += roundingGradationTests();
failures += precisionConsistencyTest();
if (failures > 0) {
throw new RuntimeException("Incurred " + failures +
" failures while testing rounding add.");
}
}
}
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6473768
* @summary Tests of BigDecimal.compareTo
* @author Joseph D. Darcy
*/
import java.math.*;
import static java.math.BigDecimal.*;
public class CompareToTests {
private static int compareToTests() {
int failures = 0;
final BigDecimal MINUS_ONE = BigDecimal.ONE.negate();
// First operand, second operand, expected compareTo result
BigDecimal [][] testCases = {
// Basics
{valueOf(0), valueOf(0), ZERO},
{valueOf(0), valueOf(1), MINUS_ONE},
{valueOf(1), valueOf(2), MINUS_ONE},
{valueOf(2), valueOf(1), ONE},
{valueOf(10), valueOf(10), ZERO},
// Significands would compare differently than scaled value
{valueOf(2,1), valueOf(2), MINUS_ONE},
{valueOf(2,-1), valueOf(2), ONE},
{valueOf(1,1), valueOf(2), MINUS_ONE},
{valueOf(1,-1), valueOf(2), ONE},
{valueOf(5,-1), valueOf(2), ONE},
// Boundary and near boundary values
{valueOf(Long.MAX_VALUE), valueOf(Long.MAX_VALUE), ZERO},
{valueOf(Long.MAX_VALUE-1), valueOf(Long.MAX_VALUE), MINUS_ONE},
{valueOf(Long.MIN_VALUE), valueOf(Long.MAX_VALUE), MINUS_ONE},
{valueOf(Long.MIN_VALUE+1), valueOf(Long.MAX_VALUE), MINUS_ONE},
{valueOf(Long.MIN_VALUE), valueOf(Long.MIN_VALUE), ZERO},
{valueOf(Long.MIN_VALUE+1), valueOf(Long.MAX_VALUE), ONE},
};
for (BigDecimal[] testCase : testCases) {
BigDecimal a = testCase[0];
BigDecimal a_negate = a.negate();
BigDecimal b = testCase[1];
BigDecimal b_negate = b.negate();
int expected = testCase[2].intValue();
failures += compareToTest(a, b, expected);
failures += compareToTest(a_negate, b, -1);
failures += compareToTest(a, b_negate, 1);
failures += compareToTest(a_negate, b_negate, -expected);
}
return failures;
}
private static int compareToTest(BigDecimal a, BigDecimal b, int expected) {
int result = a.compareTo(b);
int failed = (result==expected) ? 0 : 1;
if (result == 1) {
System.err.println("(" + a + ").compareTo(" + b + ") => " + result +
"\n\tExpected " + expected);
}
return result;
}
public static void main(String argv[]) {
int failures = 0;
failures += compareToTests();
if (failures > 0) {
throw new RuntimeException("Incurred " + failures +
" failures while testing exact compareTo.");
}
}
}
/*
* Copyright 1999 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4259453
* @summary Test string constructor of BigDecimal
*/
import java.math.BigDecimal;
public class Constructor {
public static void main(String[] args) throws Exception {
boolean nfe = false;
try {
BigDecimal bd = new BigDecimal("1.2e");
} catch (NumberFormatException e) {
nfe = true;
}
if (!nfe)
throw new Exception("Didn't throw NumberFormatException");
}
}
/*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851776 4907265 6177836
* @summary Some tests for the divide methods.
* @author Joseph D. Darcy
* @compile -source 1.5 DivideTests.java
* @run main DivideTests
*/
import java.math.*;
import static java.math.BigDecimal.*;
public class DivideTests {
// Preliminary exact divide method; could be used for comparison
// purposes.
BigDecimal anotherDivide(BigDecimal dividend, BigDecimal divisor) {
/*
* Handle zero cases first.
*/
if (divisor.signum() == 0) { // x/0
if (dividend.signum() == 0) // 0/0
throw new ArithmeticException("Division undefined"); // NaN
throw new ArithmeticException("Division by zero");
}
if (dividend.signum() == 0) // 0/y
return BigDecimal.ZERO;
else {
/*
* Determine if there is a result with a terminating
* decimal expansion. Putting aside overflow and
* underflow considerations, the existance of an exact
* result only depends on the ratio of the intVal's of the
* dividend (i.e. this) and and divisor since the scales
* of the argument just affect where the decimal point
* lies.
*
* For the ratio of (a = this.intVal) and (b =
* divisor.intVal) to have a finite decimal expansion,
* once a/b is put in lowest terms, b must be equal to
* (2^i)*(5^j) for some integer i,j >= 0. Therefore, we
* first compute to see if b_prime =(b/gcd(a,b)) is equal
* to (2^i)*(5^j).
*/
BigInteger TWO = BigInteger.valueOf(2);
BigInteger FIVE = BigInteger.valueOf(5);
BigInteger TEN = BigInteger.valueOf(10);
BigInteger divisorIntvalue = divisor.scaleByPowerOfTen(divisor.scale()).toBigInteger().abs();
BigInteger dividendIntvalue = dividend.scaleByPowerOfTen(dividend.scale()).toBigInteger().abs();
BigInteger b_prime = divisorIntvalue.divide(dividendIntvalue.gcd(divisorIntvalue));
boolean goodDivisor = false;
int i=0, j=0;
badDivisor: {
while(! b_prime.equals(BigInteger.ONE) ) {
int b_primeModTen = b_prime.mod(TEN).intValue() ;
switch(b_primeModTen) {
case 0:
// b_prime divisible by 10=2*5, increment i and j
i++;
j++;
b_prime = b_prime.divide(TEN);
break;
case 5:
// b_prime divisible by 5, increment j
j++;
b_prime = b_prime.divide(FIVE);
break;
case 2:
case 4:
case 6:
case 8:
// b_prime divisible by 2, increment i
i++;
b_prime = b_prime.divide(TWO);
break;
default: // hit something we shouldn't have
b_prime = BigInteger.ONE; // terminate loop
break badDivisor;
}
}
goodDivisor = true;
}
if( ! goodDivisor ) {
throw new ArithmeticException("Non terminating decimal expansion");
}
else {
// What is a rule for determining how many digits are
// needed? Once that is determined, cons up a new
// MathContext object and pass it on to the divide(bd,
// mc) method; precision == ?, roundingMode is unnecessary.
// Are we sure this is the right scale to use? Should
// also determine a precision-based method.
MathContext mc = new MathContext(dividend.precision() +
(int)Math.ceil(
10.0*divisor.precision()/3.0),
RoundingMode.UNNECESSARY);
// Should do some more work here to rescale, etc.
return dividend.divide(divisor, mc);
}
}
}
public static int powersOf2and5() {
int failures = 0;
for(int i = 0; i < 6; i++) {
int powerOf2 = (int)StrictMath.pow(2.0, i);
for(int j = 0; j < 6; j++) {
int powerOf5 = (int)StrictMath.pow(5.0, j);
int product;
BigDecimal bd;
try {
bd = BigDecimal.ONE.divide(new BigDecimal(product=powerOf2*powerOf5));
} catch (ArithmeticException e) {
failures++;
System.err.println((new BigDecimal(powerOf2)).toString() + " / " +
(new BigDecimal(powerOf5)).toString() + " threw an exception.");
e.printStackTrace();
}
try {
bd = new BigDecimal(powerOf2).divide(new BigDecimal(powerOf5));
} catch (ArithmeticException e) {
failures++;
System.err.println((new BigDecimal(powerOf2)).toString() + " / " +
(new BigDecimal(powerOf5)).toString() + " threw an exception.");
e.printStackTrace();
}
try {
bd = new BigDecimal(powerOf5).divide(new BigDecimal(powerOf2));
} catch (ArithmeticException e) {
failures++;
System.err.println((new BigDecimal(powerOf5)).toString() + " / " +
(new BigDecimal(powerOf2)).toString() + " threw an exception.");
e.printStackTrace();
}
}
}
return failures;
}
public static int nonTerminating() {
int failures = 0;
int[] primes = {1, 3, 7, 13, 17};
// For each pair of prime products, verify the ratio of
// non-equal products has a non-terminating expansion.
for(int i = 0; i < primes.length; i++) {
for(int j = i+1; j < primes.length; j++) {
for(int m = 0; m < primes.length; m++) {
for(int n = m+1; n < primes.length; n++) {
int dividend = primes[i] * primes[j];
int divisor = primes[m] * primes[n];
if ( ((dividend/divisor) * divisor) != dividend ) {
try {
BigDecimal quotient = (new BigDecimal(dividend).
divide(new BigDecimal(divisor)));
failures++;
System.err.println("Exact quotient " + quotient.toString() +
" returned for non-terminating fraction " +
dividend + " / " + divisor + ".");
}
catch (ArithmeticException e) {
; // Correct result
}
}
}
}
}
}
return failures;
}
public static int properScaleTests(){
int failures = 0;
BigDecimal[][] testCases = {
{new BigDecimal("1"), new BigDecimal("5"), new BigDecimal("2e-1")},
{new BigDecimal("1"), new BigDecimal("50e-1"), new BigDecimal("2e-1")},
{new BigDecimal("10e-1"), new BigDecimal("5"), new BigDecimal("2e-1")},
{new BigDecimal("1"), new BigDecimal("500e-2"), new BigDecimal("2e-1")},
{new BigDecimal("100e-2"), new BigDecimal("5"), new BigDecimal("20e-2")},
{new BigDecimal("1"), new BigDecimal("32"), new BigDecimal("3125e-5")},
{new BigDecimal("1"), new BigDecimal("64"), new BigDecimal("15625e-6")},
{new BigDecimal("1.0000000"), new BigDecimal("64"), new BigDecimal("156250e-7")},
};
for(BigDecimal[] tc : testCases) {
BigDecimal quotient;
if (! (quotient = tc[0].divide(tc[1])).equals(tc[2]) ) {
failures++;
System.err.println("Unexpected quotient from " + tc[0] + " / " + tc[1] +
"; expected " + tc[2] + " got " + quotient);
}
}
return failures;
}
public static int trailingZeroTests() {
int failures = 0;
MathContext mc = new MathContext(3, RoundingMode.FLOOR);
BigDecimal[][] testCases = {
{new BigDecimal("19"), new BigDecimal("100"), new BigDecimal("0.19")},
{new BigDecimal("21"), new BigDecimal("110"), new BigDecimal("0.190")},
};
for(BigDecimal[] tc : testCases) {
BigDecimal quotient;
if (! (quotient = tc[0].divide(tc[1], mc)).equals(tc[2]) ) {
failures++;
System.err.println("Unexpected quotient from " + tc[0] + " / " + tc[1] +
"; expected " + tc[2] + " got " + quotient);
}
}
return failures;
}
public static int scaledRoundedDivideTests() {
int failures = 0;
// Tests of the traditional scaled divide under different
// rounding modes.
// Encode rounding mode and scale for the divide in a
// BigDecimal with the significand equal to the rounding mode
// and the scale equal to the number's scale.
// {dividend, dividisor, rounding, quotient}
BigDecimal a = new BigDecimal("31415");
BigDecimal a_minus = a.negate();
BigDecimal b = new BigDecimal("10000");
BigDecimal c = new BigDecimal("31425");
BigDecimal c_minus = c.negate();
BigDecimal[][] testCases = {
{a, b, BigDecimal.valueOf(ROUND_UP, 3), new BigDecimal("3.142")},
{a_minus, b, BigDecimal.valueOf(ROUND_UP, 3), new BigDecimal("-3.142")},
{a, b, BigDecimal.valueOf(ROUND_DOWN, 3), new BigDecimal("3.141")},
{a_minus, b, BigDecimal.valueOf(ROUND_DOWN, 3), new BigDecimal("-3.141")},
{a, b, BigDecimal.valueOf(ROUND_CEILING, 3), new BigDecimal("3.142")},
{a_minus, b, BigDecimal.valueOf(ROUND_CEILING, 3), new BigDecimal("-3.141")},
{a, b, BigDecimal.valueOf(ROUND_FLOOR, 3), new BigDecimal("3.141")},
{a_minus, b, BigDecimal.valueOf(ROUND_FLOOR, 3), new BigDecimal("-3.142")},
{a, b, BigDecimal.valueOf(ROUND_HALF_UP, 3), new BigDecimal("3.142")},
{a_minus, b, BigDecimal.valueOf(ROUND_HALF_UP, 3), new BigDecimal("-3.142")},
{a, b, BigDecimal.valueOf(ROUND_DOWN, 3), new BigDecimal("3.141")},
{a_minus, b, BigDecimal.valueOf(ROUND_DOWN, 3), new BigDecimal("-3.141")},
{a, b, BigDecimal.valueOf(ROUND_HALF_EVEN, 3), new BigDecimal("3.142")},
{a_minus, b, BigDecimal.valueOf(ROUND_HALF_EVEN, 3), new BigDecimal("-3.142")},
{c, b, BigDecimal.valueOf(ROUND_HALF_EVEN, 3), new BigDecimal("3.142")},
{c_minus, b, BigDecimal.valueOf(ROUND_HALF_EVEN, 3), new BigDecimal("-3.142")},
};
for(BigDecimal tc[] : testCases) {
int scale = tc[2].scale();
int rm = tc[2].unscaledValue().intValue();
BigDecimal quotient = tc[0].divide(tc[1], scale, rm);
if (!quotient.equals(tc[3])) {
failures++;
System.err.println("Unexpected quotient from " + tc[0] + " / " + tc[1] +
" scale " + scale + " rounding mode " + RoundingMode.valueOf(rm) +
"; expected " + tc[3] + " got " + quotient);
}
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += powersOf2and5();
failures += nonTerminating();
failures += properScaleTests();
failures += trailingZeroTests();
failures += scaledRoundedDivideTests();
if (failures > 0) {
throw new RuntimeException("Incurred " + failures +
" failures while testing exact divide.");
}
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6274390
* @summary Verify {float, double}Value methods work with condensed representation
*/
import java.math.*;
public class FloatDoubleValueTests {
private static final long two2the24 = 1L<<23;
private static final long two2the53 = 1L<<52;
// Largest long that fits exactly in a float
private static final long maxFltLong = (long)(Integer.MAX_VALUE & ~(0xff));
// Largest long that fits exactly in a double
private static final long maxDblLong = Long.MAX_VALUE & ~(0x7ffL);
static void testDoubleValue0(long i, BigDecimal bd) {
if (bd.doubleValue() != i ||
bd.longValue() != i)
throw new RuntimeException("Unexpected equality failure for " +
i + "\t" + bd);
}
static void testFloatValue0(long i, BigDecimal bd) {
if (bd.floatValue() != i ||
bd.longValue() != i)
throw new RuntimeException("Unexpected equality failure for " +
i + "\t" + bd);
}
static void checkFloat(BigDecimal bd, float f) {
float fbd = bd.floatValue();
if (f != fbd ) {
String message = String.format("Bad conversion:"+
"got %g (%a)\texpected %g (%a)",
f, f, fbd, fbd);
throw new RuntimeException(message);
}
}
static void checkDouble(BigDecimal bd, double d) {
double dbd = bd.doubleValue();
if (d != dbd ) {
String message = String.format("Bad conversion:"+
"got %g (%a)\texpected %g (%a)",
d, d, dbd, dbd);
throw new RuntimeException(message);
}
}
// Test integral values that will convert exactly to both float
// and double.
static void testFloatDoubleValue() {
long longValues[] = {
0,
1,
2,
two2the24-1,
two2the24,
two2the24+1,
maxFltLong-1,
maxFltLong,
maxFltLong+1,
};
for(long i : longValues) {
BigDecimal bd1 = new BigDecimal(i);
BigDecimal bd2 = new BigDecimal(-i);
testDoubleValue0( i, bd1);
testDoubleValue0(-i, bd2);
testFloatValue0( i, bd1);
testFloatValue0(-i, bd2);
}
}
static void testDoubleValue() {
long longValues[] = {
Integer.MAX_VALUE-1,
Integer.MAX_VALUE,
(long)Integer.MAX_VALUE+1,
two2the53-1,
two2the53,
two2the53+1,
maxDblLong,
};
// Test integral values that will convert exactly to double
// but not float.
for(long i : longValues) {
BigDecimal bd1 = new BigDecimal(i);
BigDecimal bd2 = new BigDecimal(-i);
testDoubleValue0( i, bd1);
testDoubleValue0(-i, bd2);
checkFloat(bd1, (float)i);
checkFloat(bd2, -(float)i);
}
// Now check values that should not convert the same in double
for(long i = maxDblLong; i < Long.MAX_VALUE; i++) {
BigDecimal bd1 = new BigDecimal(i);
BigDecimal bd2 = new BigDecimal(-i);
checkDouble(bd1, (double)i);
checkDouble(bd2, -(double)i);
checkFloat(bd1, (float)i);
checkFloat(bd2, -(float)i);
}
checkDouble(new BigDecimal(Long.MIN_VALUE), (double)Long.MIN_VALUE);
checkDouble(new BigDecimal(Long.MAX_VALUE), (double)Long.MAX_VALUE);
}
static void testFloatValue() {
// Now check values that should not convert the same in float
for(long i = maxFltLong; i <= Integer.MAX_VALUE; i++) {
BigDecimal bd1 = new BigDecimal(i);
BigDecimal bd2 = new BigDecimal(-i);
checkFloat(bd1, (float)i);
checkFloat(bd2, -(float)i);
testDoubleValue0( i, bd1);
testDoubleValue0(-i, bd2);
}
}
public static void main(String[] args) throws Exception {
testFloatDoubleValue();
testDoubleValue();
testFloatValue();
}
}
/*
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4904082 4917089 6337226
* @summary Tests that integral division and related methods return the proper result and scale.
* @author Joseph D. Darcy
* @compile -source 1.5 IntegralDivisionTests.java
* @run main IntegralDivisionTests
*/
import java.math.*;
public class IntegralDivisionTests {
static int dividetoIntegralValueTests() {
int failures = 0;
// Exact integer quotient should have the same results from
// the exact divide and dividetoIntegralValue
// Rounded results
BigDecimal [][] moreTestCases = {
{new BigDecimal("11003"), new BigDecimal("10"), new BigDecimal("1100")},
{new BigDecimal("11003"), new BigDecimal("1e1"), new BigDecimal("1100.0")},
{new BigDecimal("1e9"), new BigDecimal("1"), new BigDecimal("1e9")},
{new BigDecimal("1e9"), new BigDecimal("1.00"), new BigDecimal("1e9")},
{new BigDecimal("1e9"), new BigDecimal("0.1"), new BigDecimal("1e10")},
{new BigDecimal("10e8"), new BigDecimal("0.1"), new BigDecimal("10e9")},
{new BigDecimal("400e1"), new BigDecimal("5"), new BigDecimal("80e1")},
{new BigDecimal("400e1"), new BigDecimal("4.999999999"), new BigDecimal("8e2")},
{new BigDecimal("40e2"), new BigDecimal("5"), new BigDecimal("8e2")},
};
for(BigDecimal [] testCase: moreTestCases) {
BigDecimal quotient;
if (! (quotient=testCase[0].divideToIntegralValue(testCase[1])).equals(testCase[2]) ){
failures++;
// BigDecimal exact = testCase[0].divide(testCase[1]);
System.err.println();
System.err.println("dividend = " + testCase[0] + " scale = " + testCase[0].scale());
System.err.println("divisor = " + testCase[1] + " scale = " + testCase[1].scale());
System.err.println("quotient = " + quotient + " scale = " + quotient.scale());
System.err.println("expected = " + testCase[2] + " scale = " + testCase[2].scale());
// System.err.println("exact = " + exact + " scale = " + exact.scale());
}
}
return failures;
}
static int dividetoIntegralValueRoundedTests() {
int failures = 0;
BigDecimal dividend = new BigDecimal("11003");
BigDecimal divisor = new BigDecimal("10");
BigDecimal [] quotients = { // Expected results with precision =
new BigDecimal("1100"), // 0
null, // 1
new BigDecimal("11e2"), // 2
new BigDecimal("110e1"), // 3
new BigDecimal("1100"), // 4
};
failures += divideContextTestPrecs(dividend, divisor, quotients);
dividend = new BigDecimal("11003");
divisor = new BigDecimal("1e1");
BigDecimal [] quotients2 = { // Expected results with precision =
new BigDecimal("1100.0"), // 0
null, // 1
new BigDecimal("11e2"), // 2
new BigDecimal("110e1"), // 3
new BigDecimal("1100"), // 4
new BigDecimal("1100.0"), // 5
};
failures += divideContextTestPrecs(dividend, divisor, quotients2);
dividend = new BigDecimal("1230000");
divisor = new BigDecimal("100");
BigDecimal [] quotients3 = { // Expected results with precision =
new BigDecimal("12300"), // 0
null, // 1
null, // 2
new BigDecimal("123e2"), // 3
new BigDecimal("1230e1"), // 4
new BigDecimal("12300"), // 5
};
failures += divideContextTestPrecs(dividend, divisor, quotients3);
dividend = new BigDecimal("33");
divisor = new BigDecimal("3");
BigDecimal [] quotients4 = { // Expected results with precision =
new BigDecimal("11"), // 0
null, // 1
new BigDecimal("11"), // 2
new BigDecimal("11"), // 3
};
failures += divideContextTestPrecs(dividend, divisor, quotients4);
dividend = new BigDecimal("34");
divisor = new BigDecimal("3");
BigDecimal [] quotients5 = { // Expected results with precision =
new BigDecimal("11"), // 0
null, // 1
new BigDecimal("11"), // 2
new BigDecimal("11"), // 3
};
failures += divideContextTestPrecs(dividend, divisor, quotients5);
return failures;
}
static int divideContextTestPrecs(BigDecimal dividend,
BigDecimal divisor,
BigDecimal[] quotients)
{
int failures = 0;
for(int i = 0; i < quotients.length; i++) {
BigDecimal result = null;
BigDecimal quotient = quotients[i];
try {
result = dividend.divideToIntegralValue(divisor,
new MathContext(i, RoundingMode.DOWN));
} catch (ArithmeticException e) {
if (quotient != null) {
failures++;
System.err.println();
System.err.println("Unexpected exception:");
System.err.println("dividend = " + dividend + " scale = " + dividend.scale());
System.err.println("divisor = " + divisor + " scale = " + divisor.scale());
System.err.println("expected = " + quotient + " scale = " + quotient.scale());
}
}
if (quotient != null) {
if (! result.equals(quotient)) {
failures++;
System.err.println();
System.err.println("Unexpected result:");
System.err.println("dividend = " + dividend + " scale = " + dividend.scale());
System.err.println("divisor = " + divisor + " scale = " + divisor.scale());
System.err.println("quotient = " + result + " scale = " + result.scale());
System.err.println("expected = " + quotient + " scale = " + quotient.scale());
System.err.println("precision = " + i);
}
} else {
if (result != null) {
failures++;
System.err.println();
System.err.println("Unexpected unexceptional result:");
System.err.println("dividend = " + dividend + " scale = " + dividend.scale());
System.err.println("divisor = " + divisor + " scale = " + divisor.scale());
System.err.println("quotient = " + result + " scale = " + result.scale());
System.err.println("precision = " + i);
}
}
}
return failures;
}
static int divideContextTests(BigDecimal dividend,
BigDecimal divisor,
BigDecimal expected,
MathContext mc) {
int failures = 0;
failures += divideContextTest(dividend, divisor, expected, mc);
failures += divideContextTest(dividend.negate(), divisor.negate(), expected, mc);
if (expected != null) {
failures += divideContextTest(dividend.negate(), divisor, expected.negate(), mc);
failures += divideContextTest(dividend, divisor.negate(), expected.negate(), mc);
}
return failures;
}
static int divideContextTest(BigDecimal dividend,
BigDecimal divisor,
BigDecimal expected,
MathContext mc)
{
int failures = 0;
BigDecimal result = null;
try {
result = dividend.divideToIntegralValue(divisor, mc);
} catch (ArithmeticException e) {
if (expected != null) {
failures++;
System.err.println();
System.err.println("Unexpected exception:");
System.err.println("dividend = " + dividend + " scale = " + dividend.scale());
System.err.println("divisor = " + divisor + " scale = " + divisor.scale());
System.err.println("expected = " + expected + " scale = " + expected.scale());
System.err.println("MathContext = " + mc);
}
}
if (expected != null) {
if (! result.equals(expected)) {
failures++;
System.err.println();
System.err.println("Unexpected result:");
System.err.println("dividend = " + dividend + " scale = " + dividend.scale());
System.err.println("divisor = " + divisor + " scale = " + divisor.scale());
System.err.println("expected = " + expected + " scale = " + expected.scale());
System.err.println("result = " + result + " scale = " + result.scale());
System.err.println("MathContext = " + mc);
}
} else {
if (result != null) {
failures++;
System.err.println();
System.err.println("Unexpected unexceptional result:");
System.err.println("dividend = " + dividend + " scale = " + dividend.scale());
System.err.println("divisor = " + divisor + " scale = " + divisor.scale());
System.err.println("quotient = " + result + " scale = " + result.scale());
System.err.println("MathConext = " + mc);
}
}
return failures;
}
static int dividetoIntegralValueScalingTests() {
int failures = 0;
BigDecimal dividend = new BigDecimal("123456789000");
BigDecimal divisor = BigDecimal.ONE;
BigDecimal expected = new BigDecimal("123456789e3");
MathContext mc = new MathContext(9,RoundingMode.DOWN);
failures += divideContextTests(dividend, divisor, expected, mc);
// 100/3 = 33 remainder 1
int [] precisions = {0, 2, 3, 4};
dividend = new BigDecimal(100);
divisor = new BigDecimal(3);
expected = new BigDecimal(33);
for(RoundingMode rm: RoundingMode.values())
for(int precision: precisions) {
failures += divideContextTests(dividend, divisor, expected,
new MathContext(precision, rm));
}
// 123000/10 = 12300 remainder 0
dividend = new BigDecimal(123000);
divisor = new BigDecimal(10);
int[] precisions1 = {0, 1, 2, 3, 4, 5};
BigDecimal[] expected1 = {
new BigDecimal("12300"),
null,
null,
new BigDecimal("123e2"),
new BigDecimal("1230e1"),
new BigDecimal("12300"),
};
for(RoundingMode rm: RoundingMode.values())
for(int i = 0; i < precisions1.length; i++) {
failures += divideContextTests(dividend, divisor,
expected1[i],
new MathContext(precisions1[i], rm));
}
// 123e3/10 = 123e2 remainder 0
dividend = new BigDecimal("123e3");
divisor = new BigDecimal(10);
int[] precisions2 = {0, 1, 2, 3, 4, 5};
BigDecimal[] expected2 = {
new BigDecimal("123e2"),
null,
null,
new BigDecimal("123e2"),
new BigDecimal("123e2"),
new BigDecimal("123e2"),
};
for(RoundingMode rm: RoundingMode.values())
for(int i = 0; i < precisions2.length; i++) {
failures += divideContextTests(dividend, divisor,
expected2[i],
new MathContext(precisions2[i], rm));
}
// 123000/1e1 = 12300.0 remainder 0
dividend = new BigDecimal("123000");
divisor = new BigDecimal("1e1");
int[] precisions3 = {0, 1, 2, 3, 4, 5, 6};
BigDecimal[] expected3 = {
new BigDecimal("12300.0"),
null,
null,
new BigDecimal("123e2"),
new BigDecimal("1230e1"),
new BigDecimal("12300"),
new BigDecimal("12300.0"),
};
for(RoundingMode rm: RoundingMode.values())
for(int i = 0; i < precisions3.length; i++) {
failures += divideContextTests(dividend, divisor,
expected3[i],
new MathContext(precisions3[i], rm));
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += dividetoIntegralValueTests();
failures += dividetoIntegralValueRoundedTests();
failures += dividetoIntegralValueScalingTests();
if (failures > 0) {
System.err.println("Encountered " + failures +
" failures while testing integral division.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6325535
* @summary Test for the rounding behavior of negate(MathContext)
* @author Joseph D. Darcy
*/
import java.math.*;
public class NegateTests {
static BigDecimal negateThenRound(BigDecimal bd, MathContext mc) {
return bd.negate().plus(mc);
}
static BigDecimal absThenRound(BigDecimal bd, MathContext mc) {
return bd.abs().plus(mc);
}
static int negateTest(BigDecimal[][] testCases, MathContext mc) {
int failures = 0;
for (BigDecimal [] testCase : testCases) {
BigDecimal bd = testCase[0];
BigDecimal neg1 = bd.negate(mc);
BigDecimal neg2 = negateThenRound(bd, mc);
BigDecimal expected = testCase[1];
if (! neg1.equals(expected) ) {
failures++;
System.err.println("(" + bd + ").negate(" + mc + ") => " +
neg1 + " != expected " + expected);
}
if (! neg1.equals(neg2) ) {
failures++;
System.err.println("(" + bd + ").negate(" + mc + ") => " +
neg1 + " != ntr " + neg2);
}
// Test abs consistency
BigDecimal abs = bd.abs(mc);
BigDecimal expectedAbs = absThenRound(bd,mc);
if (! abs.equals(expectedAbs) ) {
failures++;
System.err.println("(" + bd + ").abs(" + mc + ") => " +
abs + " != atr " + expectedAbs);
}
}
return failures;
}
static int negateTests() {
int failures = 0;
BigDecimal [][] testCasesCeiling = {
{new BigDecimal("1.3"), new BigDecimal("-1")},
{new BigDecimal("-1.3"), new BigDecimal("2")},
};
failures += negateTest(testCasesCeiling,
new MathContext(1, RoundingMode.CEILING));
BigDecimal [][] testCasesFloor = {
{new BigDecimal("1.3"), new BigDecimal("-2")},
{new BigDecimal("-1.3"), new BigDecimal("1")},
};
failures += negateTest(testCasesFloor,
new MathContext(1, RoundingMode.FLOOR));
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += negateTests();
if (failures > 0 )
throw new RuntimeException("Incurred " + failures + " failures" +
" testing the negate and/or abs.");
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4916097
* @summary Some exponent over/undeflow tests for the pow method
* @author Joseph D. Darcy
* @compile -source 1.5 PowTests.java
* @run main PowTests
*/
import java.math.*;
public class PowTests {
static int zeroAndOneTests() {
int failures = 0;
BigDecimal[][] testCases = {
{BigDecimal.valueOf(0, Integer.MAX_VALUE), new BigDecimal(0), BigDecimal.valueOf(1, 0)},
{BigDecimal.valueOf(0, Integer.MAX_VALUE), new BigDecimal(1), BigDecimal.valueOf(0, Integer.MAX_VALUE)},
{BigDecimal.valueOf(0, Integer.MAX_VALUE), new BigDecimal(2), BigDecimal.valueOf(0, Integer.MAX_VALUE)},
{BigDecimal.valueOf(0, Integer.MAX_VALUE), new BigDecimal(999999999), BigDecimal.valueOf(0, Integer.MAX_VALUE)},
{BigDecimal.valueOf(0, Integer.MIN_VALUE), new BigDecimal(0), BigDecimal.valueOf(1, 0)},
{BigDecimal.valueOf(0, Integer.MIN_VALUE), new BigDecimal(1), BigDecimal.valueOf(0, Integer.MIN_VALUE)},
{BigDecimal.valueOf(0, Integer.MIN_VALUE), new BigDecimal(2), BigDecimal.valueOf(0, Integer.MIN_VALUE)},
{BigDecimal.valueOf(0, Integer.MIN_VALUE), new BigDecimal(999999999), BigDecimal.valueOf(0, Integer.MIN_VALUE)},
{BigDecimal.valueOf(1, Integer.MAX_VALUE), new BigDecimal(0), BigDecimal.valueOf(1, 0)},
{BigDecimal.valueOf(1, Integer.MAX_VALUE), new BigDecimal(1), BigDecimal.valueOf(1, Integer.MAX_VALUE)},
{BigDecimal.valueOf(1, Integer.MAX_VALUE), new BigDecimal(2), null}, // overflow
{BigDecimal.valueOf(1, Integer.MAX_VALUE), new BigDecimal(999999999), null}, // overflow
{BigDecimal.valueOf(1, Integer.MIN_VALUE), new BigDecimal(0), BigDecimal.valueOf(1, 0)},
{BigDecimal.valueOf(1, Integer.MIN_VALUE), new BigDecimal(1), BigDecimal.valueOf(1, Integer.MIN_VALUE)},
{BigDecimal.valueOf(1, Integer.MIN_VALUE), new BigDecimal(2), null}, // underflow
{BigDecimal.valueOf(1, Integer.MIN_VALUE), new BigDecimal(999999999), null}, // underflow
};
for(BigDecimal[] testCase: testCases) {
int exponent = testCase[1].intValueExact();
BigDecimal result;
try{
result = testCase[0].pow(exponent);
if (!result.equals(testCase[2]) ) {
failures++;
System.err.println("Unexpected result while raising " +
testCase[0] +
" to the " + exponent + " power; expected " +
testCase[2] + ", got " + result + ".");
}
} catch (ArithmeticException e) {
if (testCase[2] != null) {
failures++;
System.err.println("Unexpected exception while raising " + testCase[0] +
" to the " + exponent + " power.");
}
}
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += zeroAndOneTests();
if (failures > 0) {
throw new RuntimeException("Incurred " + failures +
" failures while testing pow methods.");
}
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6334849
* @summary Tests of dropping digits near the scale threshold
* @author Joseph D. Darcy
*/
import java.math.*;
public class RoundingTests {
private static int roundingTests() {
int failures = 0;
BigDecimal bd1 = BigDecimal.valueOf(11, Integer.MIN_VALUE);
BigDecimal bd2 = null;
MathContext mc = new MathContext(1);
try {
bd2 = bd1.round(mc); // should overflow here
failures++;
System.err.printf("Did not get expected overflow rounding %s to %d digits, got %s%n",
bd1, mc.getPrecision(), bd2);
} catch(ArithmeticException e) {
; // expected
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += roundingTests();
if (failures > 0) {
System.err.println("Encountered " + failures +
" failures while testing rounding.");
throw new RuntimeException();
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4899722
* @summary Basic tests of scaleByPowerOfTen
* @author Joseph D. Darcy
*/
import java.math.*;
public class ScaleByPowerOfTenTests {
public static void main(String argv[]) {
for (int i = -10; i < 10; i++) {
BigDecimal bd = BigDecimal.ONE.scaleByPowerOfTen(i);
BigDecimal expected;
if (!bd.equals(expected = new BigDecimal(BigInteger.ONE, -i))) {
throw new RuntimeException("Unexpected result " +
bd.toString() +
"; expected " +
expected.toString());
}
bd = BigDecimal.ONE.negate().scaleByPowerOfTen(i);
if (!bd.equals(expected = new BigDecimal(BigInteger.ONE.negate(), -i))) {
throw new RuntimeException("Unexpected result " +
bd.toString() +
"; expected " +
expected.toString());
}
}
}
}
/*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6177836
* @summary Verify BigDecimal objects with collapsed values are serialized properly.
* @author Joseph D. Darcy
*/
import java.math.*;
import java.io.*;
public class SerializationTests {
static void checkSerialForm(BigDecimal bd) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(bd);
oos.flush();
oos.close();
ObjectInputStream ois = new
ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
BigDecimal tmp = (BigDecimal)ois.readObject();
if (!bd.equals(tmp) ||
bd.hashCode() != tmp.hashCode()) {
System.err.print(" original : " + bd);
System.err.println(" (hash: 0x" + Integer.toHexString(bd.hashCode()) + ")");
System.err.print("serialized : " + tmp);
System.err.println(" (hash: 0x" + Integer.toHexString(tmp.hashCode()) + ")");
throw new RuntimeException("Bad serial roundtrip");
}
}
public static void main(String[] args) throws Exception {
BigDecimal values[] = {
BigDecimal.ZERO,
BigDecimal.ONE,
BigDecimal.TEN,
new BigDecimal(0),
new BigDecimal(1),
new BigDecimal(10),
new BigDecimal(Integer.MAX_VALUE),
new BigDecimal(Long.MAX_VALUE-1),
new BigDecimal(BigInteger.valueOf(1), 1),
new BigDecimal(BigInteger.valueOf(100), 50),
};
for(BigDecimal value : values) {
checkSerialForm(value);
checkSerialForm(value.negate());
}
}
}
/*
* Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4103117 4331084 4488017 4490929 6255285 6268365
* @summary Tests the BigDecimal string constructor.
*/
import java.math.*;
import java.util.Random;
public class StringConstructor {
private static int seed = new Random().nextInt();
private static Random rnd = new Random(seed);
public static void main(String[] args) throws Exception {
constructWithError("");
constructWithError("+");
constructWithError("-");
constructWithError("+e");
constructWithError("-e");
constructWithError("e+");
constructWithError("1.-0");
constructWithError(".-123");
constructWithError("-");
constructWithError("--1.1");
constructWithError("-+1.1");
constructWithError("+-1.1");
constructWithError("1-.1");
constructWithError("1+.1");
constructWithError("1.111+1");
constructWithError("1.111-1");
constructWithError("11.e+");
constructWithError("11.e-");
constructWithError("11.e+-");
constructWithError("11.e-+");
constructWithError("11.e-+1");
constructWithError("11.e+-1");
// Range checks
constructWithError("1e"+Integer.MIN_VALUE);
constructWithError("10e"+Integer.MIN_VALUE);
constructWithError("0.01e"+Integer.MIN_VALUE);
constructWithError("1e"+((long)Integer.MIN_VALUE-1));
constructWithError("1e"+((long)Integer.MAX_VALUE + 1));
leadingExponentZeroTest();
nonAsciiZeroTest();
// Roundtrip tests
for (int i=0; i<100; i++) {
int size = rnd.nextInt(100) + 1;
BigInteger bi = new BigInteger(size, rnd);
if (rnd.nextBoolean())
bi = bi.negate();
int decimalLength = bi.toString().length();
int scale = rnd.nextInt(decimalLength);
BigDecimal bd = new BigDecimal(bi, scale);
String bdString = bd.toString();
// System.err.println("bi" + bi.toString() + "\tscale " + scale);
// System.err.println("bd string: " + bdString);
BigDecimal bdDoppel = new BigDecimal(bdString);
if (!bd.equals(bdDoppel)) {
System.err.println("Random number seed = " + seed);
System.err.println("bd string: scale: " + bd.scale() +
"\t" + bdString);
System.err.println("bd doppel: scale: " + bdDoppel.scale() +
"\t" + bdDoppel.toString());
throw new RuntimeException("String constructor failure.");
}
}
}
/*
* Verify precision is set properly if the significand has
* non-ASCII leading zeros.
*/
private static void nonAsciiZeroTest() {
String values[] = {
"00004e5",
"\u0660\u0660\u0660\u06604e5",
};
BigDecimal expected = new BigDecimal("4e5");
for(String s : values) {
BigDecimal tmp = new BigDecimal(s);
// System.err.println("Testing " + s);
if (! expected.equals(tmp) || tmp.precision() != 1) {
System.err.println("Bad conversion of " + s + "got " +
tmp + "precision = " + tmp.precision());
throw new RuntimeException("String constructor failure.");
}
}
}
private static void leadingExponentZeroTest() {
BigDecimal twelve = new BigDecimal("12");
BigDecimal onePointTwo = new BigDecimal("1.2");
String start = "1.2e0";
String end = "1";
String middle = "";
// Test with more excess zeros than the largest number of
// decimal digits needed to represent a long
int limit = ((int)Math.log10(Long.MAX_VALUE)) + 6;
for(int i = 0; i < limit; i++, middle += "0") {
String t1 = start + middle;
String t2 = t1 + end;
// System.out.println(i + "\t" + t1 + "\t" + t2);
testString(t1, onePointTwo);
testString(t2, twelve);
}
}
private static void testString(String s, BigDecimal expected) {
testString0(s, expected);
testString0(switchZero(s), expected);
}
private static void testString0(String s, BigDecimal expected) {
if (!expected.equals(new BigDecimal(s)))
throw new RuntimeException(s + " is not equal to " + expected);
}
private static String switchZero(String s) {
return s.replace('0', '\u0660'); // Arabic-Indic zero
}
private static void constructWithError(String badString) {
try {
BigDecimal d = new BigDecimal(badString);
throw new RuntimeException(badString + " accepted");
} catch(NumberFormatException e) {
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4108852
* @summary A few tests of stripTrailingZeros
* @author Joseph D. Darcy
*/
import java.math.*;
public class StrippingZerosTest {
public static void main(String argv[]) {
BigDecimal [][] testCases = {
{new BigDecimal("1.00000"), new BigDecimal("1")},
{new BigDecimal("1.000"), new BigDecimal("1")},
{new BigDecimal("1"), new BigDecimal("1")},
{new BigDecimal("0.1234"), new BigDecimal("0.1234")},
{new BigDecimal("0.12340"), new BigDecimal("0.1234")},
{new BigDecimal("0.12340000000"), new BigDecimal("0.1234")},
{new BigDecimal("1234.5678"), new BigDecimal("1234.5678")},
{new BigDecimal("1234.56780"), new BigDecimal("1234.5678")},
{new BigDecimal("1234.567800000"), new BigDecimal("1234.5678")},
{new BigDecimal("0"), new BigDecimal("0")},
{new BigDecimal("0e100"), new BigDecimal("0e100")},
{new BigDecimal("0e-100"), new BigDecimal("0e-100")},
{new BigDecimal("10"), new BigDecimal("1e1")},
{new BigDecimal("20"), new BigDecimal("2e1")},
{new BigDecimal("100"), new BigDecimal("1e2")},
{new BigDecimal("1000000000"), new BigDecimal("1e9")},
{new BigDecimal("100000000e1"), new BigDecimal("1e9")},
{new BigDecimal("10000000e2"), new BigDecimal("1e9")},
{new BigDecimal("1000000e3"), new BigDecimal("1e9")},
{new BigDecimal("100000e4"), new BigDecimal("1e9")},
};
for(int i = 0; i < testCases.length; i++) {
if (!(testCases[i][0]).stripTrailingZeros().equals(testCases[i][1])) {
throw new RuntimeException("For input " + testCases[i][0].toString() +
" did not received expected result " +
testCases[i][1].toString() + ", got " +
testCases[i][0].stripTrailingZeros());
}
testCases[i][0] = testCases[i][0].negate();
testCases[i][1] = testCases[i][1].negate();
if (!(testCases[i][0]).stripTrailingZeros().equals(testCases[i][1])) {
throw new RuntimeException("For input " + testCases[i][0].toString() +
" did not received expected result " +
testCases[i][1].toString() + ", got " +
testCases[i][0].stripTrailingZeros());
}
}
}
}
/*
* Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4984872
* @summary Basic tests of toPlainString method
* @author Joseph D. Darcy
* @compile -source 1.5 ToPlainStringTests.java
* @run main ToPlainStringTests
*/
import java.math.*;
public class ToPlainStringTests {
public static void main(String argv[]) {
String [][] testCases = {
{"0", "0"},
{"1", "1"},
{"10", "10"},
{"2e1", "20"},
{"3e2", "300"},
{"4e3", "4000"},
{"5e4", "50000"},
{"6e5", "600000"},
{"7e6", "7000000"},
{"8e7", "80000000"},
{"9e8", "900000000"},
{"1e9", "1000000000"},
{".0", "0.0"},
{".1", "0.1"},
{".10", "0.10"},
{"1e-1", "0.1"},
{"1e-1", "0.1"},
{"2e-2", "0.02"},
{"3e-3", "0.003"},
{"4e-4", "0.0004"},
{"5e-5", "0.00005"},
{"6e-6", "0.000006"},
{"7e-7", "0.0000007"},
{"8e-8", "0.00000008"},
{"9e-9", "0.000000009"},
{"9000e-12", "0.000000009000"},
};
int errors = 0;
for(String[] testCase: testCases) {
BigDecimal bd = new BigDecimal(testCase[0]);
String s;
if (!(s=bd.toPlainString()).equals(testCase[1])) {
errors++;
System.err.println("Unexpected plain result ``" +
s + "'' from BigDecimal " +
bd);
}
if (!(s=("-"+bd.toPlainString())).equals("-"+testCase[1])) {
errors++;
System.err.println("Unexpected plain result ``" +
s + "'' from BigDecimal " +
bd);
}
}
if(errors > 0)
throw new RuntimeException(errors + " errors during run.");
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4902952 4905407 4916149
* @summary Tests that the scale of zero is propagated properly and has the proper effect.
* @author Joseph D. Darcy
* @compile -source 1.5 ZeroScalingTests.java
* @run main ZeroScalingTests
*/
import java.math.*;
import java.util.*;
public class ZeroScalingTests {
static MathContext longEnough = new MathContext(50, RoundingMode.UNNECESSARY);
static BigDecimal[] zeros = new BigDecimal[23];
static {
for(int i = 0; i < 21; i++) {
zeros[i] = new BigDecimal(BigInteger.ZERO, i-10);
}
zeros[21] = new BigDecimal(BigInteger.ZERO, Integer.MIN_VALUE);
zeros[22] = new BigDecimal(BigInteger.ZERO, Integer.MAX_VALUE);
}
static BigDecimal element = BigDecimal.valueOf(100, -2);
static MathContext contexts[] = {
new MathContext(0, RoundingMode.UNNECESSARY),
new MathContext(100, RoundingMode.UNNECESSARY),
new MathContext(5, RoundingMode.UNNECESSARY),
new MathContext(4, RoundingMode.UNNECESSARY),
new MathContext(3, RoundingMode.UNNECESSARY),
new MathContext(2, RoundingMode.UNNECESSARY),
new MathContext(1, RoundingMode.UNNECESSARY),
};
static int addTests() {
int failures = 0;
for(BigDecimal zero1: zeros) {
for(BigDecimal zero2: zeros) {
BigDecimal expected = new BigDecimal(BigInteger.ZERO,
Math.max(zero1.scale(), zero2.scale()));
BigDecimal result;
if(! (result=zero1.add(zero2)).equals(expected) ) {
failures++;
System.err.println("For classic exact add, expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
if(! (result=zero1.add(zero2, MathContext.UNLIMITED)).equals(expected) ) {
failures++;
System.err.println("For UNLIMITED math context add," +
" expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
if(! (result=zero1.add(zero2, longEnough)).equals(expected) ) {
failures++;
System.err.println("For longEnough math context add," +
" expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
}
}
// Test effect of adding zero to a nonzero value.
for (MathContext mc: contexts) {
for (BigDecimal zero: zeros) {
if (Math.abs((long)zero.scale()) < 100 ) {
int preferredScale = Math.max(zero.scale(), element.scale());
if (mc.getPrecision() != 0) {
if (preferredScale < -4 )
preferredScale = -4;
else if (preferredScale > -(5 - mc.getPrecision())) {
preferredScale = -(5 - mc.getPrecision());
}
}
/*
System.err.println("\n " + element + " +\t" + zero + " =\t" + result);
System.err.println("scales" + element.scale() + " \t" + zero.scale() +
" \t " + result.scale() + "\t precison = " + mc.getPrecision());
System.err.println("expected scale = " + preferredScale);
*/
BigDecimal result = element.add(zero, mc);
if (result.scale() != preferredScale ||
result.compareTo(element) != 0) {
failures++;
System.err.println("Expected scale " + preferredScale +
" result scale was " + result.scale() +
" ; value was " + result);
}
result = zero.add(element, mc);
if (result.scale() != preferredScale ||
result.compareTo(element) != 0) {
failures++;
System.err.println("Expected scale " + preferredScale +
" result scale was " + result.scale() +
" ; value was " + result);
}
result = element.negate().add(zero, mc);
if (result.scale() != preferredScale ||
result.compareTo(element.negate()) != 0) {
failures++;
System.err.println("Expected scale " + preferredScale +
" result scale was " + result.scale() +
" ; value was " + result);
}
result = zero.add(element.negate(), mc);
if (result.scale() != preferredScale ||
result.compareTo(element.negate()) != 0) {
failures++;
System.err.println("Expected scale " + preferredScale +
" result scale was " + result.scale() +
" ; value was " + result);
}
}
}
}
return failures;
}
static int subtractTests() {
int failures = 0;
for(BigDecimal zero1: zeros) {
for(BigDecimal zero2: zeros) {
BigDecimal expected = new BigDecimal(BigInteger.ZERO,
Math.max(zero1.scale(), zero2.scale()));
BigDecimal result;
if(! (result=zero1.subtract(zero2)).equals(expected) ) {
failures++;
System.err.println("For classic exact subtract, expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
if(! (result=zero1.subtract(zero2, MathContext.UNLIMITED)).equals(expected) ) {
failures++;
System.err.println("For UNLIMITED math context subtract," +
" expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
if(! (result=zero1.subtract(zero2, longEnough)).equals(expected) ) {
failures++;
System.err.println("For longEnough math context subtract," +
" expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
}
}
// Test effect of adding zero to a nonzero value.
for (MathContext mc: contexts) {
for (BigDecimal zero: zeros) {
if (Math.abs((long)zero.scale()) < 100 ) {
int preferredScale = Math.max(zero.scale(), element.scale());
if (mc.getPrecision() != 0) {
if (preferredScale < -4 )
preferredScale = -4;
else if (preferredScale > -(5 - mc.getPrecision())) {
preferredScale = -(5 - mc.getPrecision());
}
}
/*
System.err.println("\n " + element + " +\t" + zero + " =\t" + result);
System.err.println("scales" + element.scale() + " \t" + zero.scale() +
" \t " + result.scale() + "\t precison = " + mc.getPrecision());
System.err.println("expected scale = " + preferredScale);
*/
BigDecimal result = element.subtract(zero, mc);
if (result.scale() != preferredScale ||
result.compareTo(element) != 0) {
failures++;
System.err.println("Expected scale " + preferredScale +
" result scale was " + result.scale() +
" ; value was " + result);
}
result = zero.subtract(element, mc);
if (result.scale() != preferredScale ||
result.compareTo(element.negate()) != 0) {
failures++;
System.err.println("Expected scale " + preferredScale +
" result scale was " + result.scale() +
" ; value was " + result);
}
result = element.negate().subtract(zero, mc);
if (result.scale() != preferredScale ||
result.compareTo(element.negate()) != 0) {
failures++;
System.err.println("Expected scale " + preferredScale +
" result scale was " + result.scale() +
" ; value was " + result);
}
result = zero.subtract(element.negate(), mc);
if (result.scale() != preferredScale ||
result.compareTo(element) != 0) {
failures++;
System.err.println("Expected scale " + preferredScale +
" result scale was " + result.scale() +
" ; value was " + result);
}
}
}
}
return failures;
}
static int multiplyTests() {
int failures = 0;
BigDecimal ones[] = {
BigDecimal.valueOf(1, 0),
BigDecimal.valueOf(10, 1),
BigDecimal.valueOf(1000, 3),
BigDecimal.valueOf(100000000, 8),
};
List<BigDecimal> values = new LinkedList<BigDecimal>();
values.addAll(Arrays.asList(zeros));
values.addAll(Arrays.asList(ones));
for(BigDecimal zero1: zeros) {
for(BigDecimal value: values) {
BigDecimal expected = new BigDecimal(BigInteger.ZERO,
(int)Math.min(Math.max((long)zero1.scale()+value.scale(),
Integer.MIN_VALUE ),
Integer.MAX_VALUE ) );
BigDecimal result;
if(! (result=zero1.multiply(value)).equals(expected) ) {
failures++;
System.err.println("For classic exact multiply, expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
if(! (result=zero1.multiply(value, MathContext.UNLIMITED)).equals(expected) ) {
failures++;
System.err.println("For UNLIMITED math context multiply," +
" expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
if(! (result=zero1.multiply(value, longEnough)).equals(expected) ) {
failures++;
System.err.println("For longEnough math context multiply," +
" expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
}
}
return failures;
}
static int divideTests() {
int failures = 0;
BigDecimal [] ones = {
BigDecimal.valueOf(1, 0),
BigDecimal.valueOf(10, -1),
BigDecimal.valueOf(100, -2),
BigDecimal.valueOf(1000, -3),
BigDecimal.valueOf(1000000, -5),
};
for(BigDecimal one: ones) {
for(BigDecimal zero: zeros) {
BigDecimal expected = new BigDecimal(BigInteger.ZERO,
(int)Math.min(Math.max((long)zero.scale() - one.scale(),
Integer.MIN_VALUE ),
Integer.MAX_VALUE ) );
BigDecimal result;
if(! (result=zero.divide(one)).equals(expected) ) {
failures++;
System.err.println("For classic exact divide, expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
if(! (result=zero.divide(one, MathContext.UNLIMITED)).equals(expected) ) {
failures++;
System.err.println("For UNLIMITED math context divide," +
" expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
if(! (result=zero.divide(one, longEnough)).equals(expected) ) {
failures++;
System.err.println("For longEnough math context divide," +
" expected scale of " +
expected.scale() + "; got " +
result.scale() + ".");
}
}
}
return failures;
}
static int setScaleTests() {
int failures = 0;
int scales[] = {
Integer.MIN_VALUE,
Integer.MIN_VALUE+1,
-10000000,
-3,
-2,
-1,
0,
1,
2,
3,
10,
10000000,
Integer.MAX_VALUE-1,
Integer.MAX_VALUE
};
for(BigDecimal zero: zeros) {
for(int scale: scales) {
try {
BigDecimal bd = zero.setScale(scale);
}
catch (ArithmeticException e) {
failures++;
System.err.println("Exception when trying to set a scale of " + scale +
" on " + zero);
}
}
}
return failures;
}
static int toEngineeringStringTests() {
int failures = 0;
String [][] testCases = {
{"0E+10", "0.00E+12"},
{"0E+9", "0E+9"},
{"0E+8", "0.0E+9"},
{"0E+7", "0.00E+9"},
{"0E-10", "0.0E-9"},
{"0E-9", "0E-9"},
{"0E-8", "0.00E-6"},
{"0E-7", "0.0E-6"},
};
for(String[] testCase: testCases) {
BigDecimal bd = new BigDecimal(testCase[0]);
String result = bd.toEngineeringString();
if (!result.equals(testCase[1]) ||
!bd.equals(new BigDecimal(result))) {
failures++;
System.err.println("From input ``" + testCase[0] + ",'' " +
" bad engineering string output ``" + result +
"''; expected ``" + testCase[1] + ".''");
}
}
return failures;
}
static int ulpTests() {
int failures = 0;
for(BigDecimal zero: zeros) {
BigDecimal result;
BigDecimal expected = BigDecimal.valueOf(1, zero.scale());
if (! (result=zero.ulp()).equals(expected) ) {
failures++;
System.err.println("Unexpected ulp value for zero value " +
zero + "; expected " + expected +
", got " + result);
}
}
return failures;
}
public static void main(String argv[]) {
int failures = 0;
failures += addTests();
failures += subtractTests();
failures += multiplyTests();
failures += divideTests();
failures += setScaleTests();
failures += toEngineeringStringTests();
failures += ulpTests();
if (failures > 0 ) {
throw new RuntimeException("Incurred " + failures + " failures" +
" testing the preservation of zero scales.");
}
}
}
/*
* Copyright 1998-2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4181191 4161971 4227146 4194389 4823171 4624738 4812225
* @summary tests methods in BigInteger
* @run main/timeout=400 BigIntegerTest
* @author madbot
*/
import java.util.Random;
import java.math.BigInteger;
import java.io.*;
/**
* This is a simple test class created to ensure that the results
* generated by BigInteger adhere to certain identities. Passing
* this test is a strong assurance that the BigInteger operations
* are working correctly.
*
* Three arguments may be specified which give the number of
* decimal digits you desire in the three batches of test numbers.
*
* The tests are performed on arrays of random numbers which are
* generated by a Random class as well as special cases which
* throw in boundary numbers such as 0, 1, maximum sized, etc.
*
*/
public class BigIntegerTest {
static Random rnd = new Random();
static int size = 1000; // numbers per batch
static boolean failure = false;
// Some variables for sizing test numbers in bits
private static int order1 = 100;
private static int order2 = 60;
private static int order3 = 30;
public static void pow() {
int failCount1 = 0;
for (int i=0; i<size; i++) {
int power = rnd.nextInt(6) +2;
BigInteger x = fetchNumber(order1);
BigInteger y = x.pow(power);
BigInteger z = x;
for (int j=1; j<power; j++)
z = z.multiply(x);
if (!y.equals(z))
failCount1++;
}
report("pow", failCount1);
}
public static void arithmetic() {
int failCount = 0;
for (int i=0; i<size; i++) {
BigInteger x = fetchNumber(order1);
while(x.compareTo(BigInteger.ZERO) != 1)
x = fetchNumber(order1);
BigInteger y = fetchNumber(order1/2);
while(x.compareTo(y) == -1)
y = fetchNumber(order1/2);
if (y.equals(BigInteger.ZERO))
y = y.add(BigInteger.ONE);
BigInteger baz = x.divide(y);
baz = baz.multiply(y);
baz = baz.add(x.remainder(y));
baz = baz.subtract(x);
if (!baz.equals(BigInteger.ZERO))
failCount++;
}
report("Arithmetic I", failCount);
failCount = 0;
for (int i=0; i<100; i++) {
BigInteger x = fetchNumber(order1);
while(x.compareTo(BigInteger.ZERO) != 1)
x = fetchNumber(order1);
BigInteger y = fetchNumber(order1/2);
while(x.compareTo(y) == -1)
y = fetchNumber(order1/2);
if (y.equals(BigInteger.ZERO))
y = y.add(BigInteger.ONE);
BigInteger baz[] = x.divideAndRemainder(y);
baz[0] = baz[0].multiply(y);
baz[0] = baz[0].add(baz[1]);
baz[0] = baz[0].subtract(x);
if (!baz[0].equals(BigInteger.ZERO))
failCount++;
}
report("Arithmetic II", failCount);
}
public static void bitCount() {
int failCount = 0;
for (int i=0; i<size*10; i++) {
int x = rnd.nextInt();
BigInteger bigX = BigInteger.valueOf((long)x);
int bit = (x < 0 ? 0 : 1);
int tmp = x, bitCount = 0;
for (int j=0; j<32; j++) {
bitCount += ((tmp & 1) == bit ? 1 : 0);
tmp >>= 1;
}
if (bigX.bitCount() != bitCount) {
//System.err.println(x+": "+bitCount+", "+bigX.bitCount());
failCount++;
}
}
report("Bit Count", failCount);
}
public static void bitLength() {
int failCount = 0;
for (int i=0; i<size*10; i++) {
int x = rnd.nextInt();
BigInteger bigX = BigInteger.valueOf((long)x);
int signBit = (x < 0 ? 0x80000000 : 0);
int tmp = x, bitLength, j;
for (j=0; j<32 && (tmp & 0x80000000)==signBit; j++)
tmp <<= 1;
bitLength = 32 - j;
if (bigX.bitLength() != bitLength) {
//System.err.println(x+": "+bitLength+", "+bigX.bitLength());
failCount++;
}
}
report("BitLength", failCount);
}
public static void bitOps() {
int failCount1 = 0, failCount2 = 0, failCount3 = 0;
for (int i=0; i<size*5; i++) {
BigInteger x = fetchNumber(order1);
BigInteger y;
/* Test setBit and clearBit (and testBit) */
if (x.signum() < 0) {
y = BigInteger.valueOf(-1);
for (int j=0; j<x.bitLength(); j++)
if (!x.testBit(j))
y = y.clearBit(j);
} else {
y = BigInteger.ZERO;
for (int j=0; j<x.bitLength(); j++)
if (x.testBit(j))
y = y.setBit(j);
}
if (!x.equals(y))
failCount1++;
/* Test flipBit (and testBit) */
y = BigInteger.valueOf(x.signum()<0 ? -1 : 0);
for (int j=0; j<x.bitLength(); j++)
if (x.signum()<0 ^ x.testBit(j))
y = y.flipBit(j);
if (!x.equals(y))
failCount2++;
}
report("clearBit/testBit", failCount1);
report("flipBit/testBit", failCount2);
for (int i=0; i<size*5; i++) {
BigInteger x = fetchNumber(order1);
/* Test getLowestSetBit() */
int k = x.getLowestSetBit();
if (x.signum() == 0) {
if (k != -1)
failCount3++;
} else {
BigInteger z = x.and(x.negate());
int j;
for (j=0; j<z.bitLength() && !z.testBit(j); j++)
;
if (k != j)
failCount3++;
}
}
report("getLowestSetBit", failCount3);
}
public static void bitwise() {
/* Test identity x^y == x|y &~ x&y */
int failCount = 0;
for (int i=0; i<size; i++) {
BigInteger x = fetchNumber(order1);
BigInteger y = fetchNumber(order1);
BigInteger z = x.xor(y);
BigInteger w = x.or(y).andNot(x.and(y));
if (!z.equals(w))
failCount++;
}
report("Logic (^ | & ~)", failCount);
/* Test identity x &~ y == ~(~x | y) */
failCount = 0;
for (int i=0; i<size; i++) {
BigInteger x = fetchNumber(order1);
BigInteger y = fetchNumber(order1);
BigInteger z = x.andNot(y);
BigInteger w = x.not().or(y).not();
if (!z.equals(w))
failCount++;
}
report("Logic (&~ | ~)", failCount);
}
public static void shift() {
int failCount1 = 0;
int failCount2 = 0;
int failCount3 = 0;
for (int i=0; i<100; i++) {
BigInteger x = fetchNumber(order1);
int n = Math.abs(rnd.nextInt()%200);
if (!x.shiftLeft(n).equals
(x.multiply(BigInteger.valueOf(2L).pow(n))))
failCount1++;
BigInteger y[] =x.divideAndRemainder(BigInteger.valueOf(2L).pow(n));
BigInteger z = (x.signum()<0 && y[1].signum()!=0
? y[0].subtract(BigInteger.ONE)
: y[0]);
BigInteger b = x.shiftRight(n);
if (!b.equals(z)) {
System.err.println("Input is "+x.toString(2));
System.err.println("shift is "+n);
System.err.println("Divided "+z.toString(2));
System.err.println("Shifted is "+b.toString(2));
if (b.toString().equals(z.toString()))
System.err.println("Houston, we have a problem.");
failCount2++;
}
if (!x.shiftLeft(n).shiftRight(n).equals(x))
failCount3++;
}
report("baz shiftLeft", failCount1);
report("baz shiftRight", failCount2);
report("baz shiftLeft/Right", failCount3);
}
public static void divideAndRemainder() {
int failCount1 = 0;
for (int i=0; i<size; i++) {
BigInteger x = fetchNumber(order1).abs();
while(x.compareTo(BigInteger.valueOf(3L)) != 1)
x = fetchNumber(order1).abs();
BigInteger z = x.divide(BigInteger.valueOf(2L));
BigInteger y[] = x.divideAndRemainder(x);
if (!y[0].equals(BigInteger.ONE)) {
failCount1++;
System.err.println("fail1 x :"+x);
System.err.println(" y :"+y);
}
else if (!y[1].equals(BigInteger.ZERO)) {
failCount1++;
System.err.println("fail2 x :"+x);
System.err.println(" y :"+y);
}
y = x.divideAndRemainder(z);
if (!y[0].equals(BigInteger.valueOf(2))) {
failCount1++;
System.err.println("fail3 x :"+x);
System.err.println(" y :"+y);
}
}
report("divideAndRemainder I", failCount1);
}
public static void stringConv() {
int failCount = 0;
for (int i=0; i<100; i++) {
byte xBytes[] = new byte[Math.abs(rnd.nextInt())%100+1];
rnd.nextBytes(xBytes);
BigInteger x = new BigInteger(xBytes);
for (int radix=2; radix < 37; radix++) {
String result = x.toString(radix);
BigInteger test = new BigInteger(result, radix);
if (!test.equals(x)) {
failCount++;
System.err.println("BigInteger toString: "+x);
System.err.println("Test: "+test);
System.err.println(radix);
}
}
}
report("String Conversion", failCount);
}
public static void byteArrayConv() {
int failCount = 0;
for (int i=0; i<size; i++) {
BigInteger x = fetchNumber(order1);
while (x.equals(BigInteger.ZERO))
x = fetchNumber(order1);
BigInteger y = new BigInteger(x.toByteArray());
if (!x.equals(y)) {
failCount++;
System.err.println("orig is "+x);
System.err.println("new is "+y);
}
}
report("Array Conversion", failCount);
}
public static void modInv() {
int failCount = 0, successCount = 0, nonInvCount = 0;
for (int i=0; i<size; i++) {
BigInteger x = fetchNumber(order1);
while(x.equals(BigInteger.ZERO))
x = fetchNumber(order1);
BigInteger m = fetchNumber(order1).abs();
while(m.compareTo(BigInteger.ONE) != 1)
m = fetchNumber(order1).abs();
try {
BigInteger inv = x.modInverse(m);
BigInteger prod = inv.multiply(x).remainder(m);
if (prod.signum() == -1)
prod = prod.add(m);
if (prod.equals(BigInteger.ONE))
successCount++;
else
failCount++;
} catch(ArithmeticException e) {
nonInvCount++;
}
}
report("Modular Inverse", failCount);
}
public static void modExp() {
int failCount = 0;
for (int i=0; i<size/10; i++) {
BigInteger m = fetchNumber(order1).abs();
while(m.compareTo(BigInteger.ONE) != 1)
m = fetchNumber(order1).abs();
BigInteger base = fetchNumber(order2);
BigInteger exp = fetchNumber(8).abs();
BigInteger z = base.modPow(exp, m);
BigInteger w = base.pow(exp.intValue()).mod(m);
if (!z.equals(w)) {
System.err.println("z is "+z);
System.err.println("w is "+w);
System.err.println("mod is "+m);
System.err.println("base is "+base);
System.err.println("exp is "+exp);
failCount++;
}
}
report("Exponentiation I", failCount);
}
// This test is based on Fermat's theorem
// which is not ideal because base must not be multiple of modulus
// and modulus must be a prime or pseudoprime (Carmichael number)
public static void modExp2() {
int failCount = 0;
for (int i=0; i<10; i++) {
BigInteger m = new BigInteger(100, 5, rnd);
while(m.compareTo(BigInteger.ONE) != 1)
m = new BigInteger(100, 5, rnd);
BigInteger exp = m.subtract(BigInteger.ONE);
BigInteger base = fetchNumber(order1).abs();
while(base.compareTo(m) != -1)
base = fetchNumber(order1).abs();
while(base.equals(BigInteger.ZERO))
base = fetchNumber(order1).abs();
BigInteger one = base.modPow(exp, m);
if (!one.equals(BigInteger.ONE)) {
System.err.println("m is "+m);
System.err.println("base is "+base);
System.err.println("exp is "+exp);
failCount++;
}
}
report("Exponentiation II", failCount);
}
private static final int[] mersenne_powers = {
521, 607, 1279, 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937,
21701, 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433,
1257787, 1398269, 2976221, 3021377, 6972593, 13466917 };
private static final long[] carmichaels = {
561,1105,1729,2465,2821,6601,8911,10585,15841,29341,41041,46657,52633,
62745,63973,75361,101101,115921,126217,162401,172081,188461,252601,
278545,294409,314821,334153,340561,399001,410041,449065,488881,512461,
225593397919L };
// Note: testing the larger ones takes too long.
private static final int NUM_MERSENNES_TO_TEST = 7;
// Note: this constant used for computed Carmichaels, not the array above
private static final int NUM_CARMICHAELS_TO_TEST = 5;
private static final String[] customer_primes = {
"120000000000000000000000000000000019",
"633825300114114700748351603131",
"1461501637330902918203684832716283019651637554291",
"779626057591079617852292862756047675913380626199",
"857591696176672809403750477631580323575362410491",
"910409242326391377348778281801166102059139832131",
"929857869954035706722619989283358182285540127919",
"961301750640481375785983980066592002055764391999",
"1267617700951005189537696547196156120148404630231",
"1326015641149969955786344600146607663033642528339" };
private static final BigInteger ZERO = BigInteger.ZERO;
private static final BigInteger ONE = BigInteger.ONE;
private static final BigInteger TWO = new BigInteger("2");
private static final BigInteger SIX = new BigInteger("6");
private static final BigInteger TWELVE = new BigInteger("12");
private static final BigInteger EIGHTEEN = new BigInteger("18");
public static void prime() {
BigInteger p1, p2, c1;
int failCount = 0;
// Test consistency
for(int i=0; i<10; i++) {
p1 = BigInteger.probablePrime(100, rnd);
if (!p1.isProbablePrime(100)) {
System.err.println("Consistency "+p1.toString(16));
failCount++;
}
}
// Test some known Mersenne primes (2^n)-1
// The array holds the exponents, not the numbers being tested
for (int i=0; i<NUM_MERSENNES_TO_TEST; i++) {
p1 = new BigInteger("2");
p1 = p1.pow(mersenne_powers[i]);
p1 = p1.subtract(BigInteger.ONE);
if (!p1.isProbablePrime(100)) {
System.err.println("Mersenne prime "+i+ " failed.");
failCount++;
}
}
// Test some primes reported by customers as failing in the past
for (int i=0; i<customer_primes.length; i++) {
p1 = new BigInteger(customer_primes[i]);
if (!p1.isProbablePrime(100)) {
System.err.println("Customer prime "+i+ " failed.");
failCount++;
}
}
// Test some known Carmichael numbers.
for (int i=0; i<carmichaels.length; i++) {
c1 = BigInteger.valueOf(carmichaels[i]);
if(c1.isProbablePrime(100)) {
System.err.println("Carmichael "+i+ " reported as prime.");
failCount++;
}
}
// Test some computed Carmichael numbers.
// Numbers of the form (6k+1)(12k+1)(18k+1) are Carmichael numbers if
// each of the factors is prime
int found = 0;
BigInteger f1 = new BigInteger(40, 100, rnd);
while (found < NUM_CARMICHAELS_TO_TEST) {
BigInteger k = null;
BigInteger f2, f3;
f1 = f1.nextProbablePrime();
BigInteger[] result = f1.subtract(ONE).divideAndRemainder(SIX);
if (result[1].equals(ZERO)) {
k = result[0];
f2 = k.multiply(TWELVE).add(ONE);
if (f2.isProbablePrime(100)) {
f3 = k.multiply(EIGHTEEN).add(ONE);
if (f3.isProbablePrime(100)) {
c1 = f1.multiply(f2).multiply(f3);
if (c1.isProbablePrime(100)) {
System.err.println("Computed Carmichael "
+c1.toString(16));
failCount++;
}
found++;
}
}
}
f1 = f1.add(TWO);
}
// Test some composites that are products of 2 primes
for (int i=0; i<50; i++) {
p1 = BigInteger.probablePrime(100, rnd);
p2 = BigInteger.probablePrime(100, rnd);
c1 = p1.multiply(p2);
if (c1.isProbablePrime(100)) {
System.err.println("Composite failed "+c1.toString(16));
failCount++;
}
}
for (int i=0; i<4; i++) {
p1 = BigInteger.probablePrime(600, rnd);
p2 = BigInteger.probablePrime(600, rnd);
c1 = p1.multiply(p2);
if (c1.isProbablePrime(100)) {
System.err.println("Composite failed "+c1.toString(16));
failCount++;
}
}
report("Prime", failCount);
}
private static final long[] primesTo100 = {
2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97
};
private static final long[] aPrimeSequence = {
1999999003L, 1999999013L, 1999999049L, 1999999061L, 1999999081L,
1999999087L, 1999999093L, 1999999097L, 1999999117L, 1999999121L,
1999999151L, 1999999171L, 1999999207L, 1999999219L, 1999999271L,
1999999321L, 1999999373L, 1999999423L, 1999999439L, 1999999499L,
1999999553L, 1999999559L, 1999999571L, 1999999609L, 1999999613L,
1999999621L, 1999999643L, 1999999649L, 1999999657L, 1999999747L,
1999999763L, 1999999777L, 1999999811L, 1999999817L, 1999999829L,
1999999853L, 1999999861L, 1999999871L, 1999999873
};
public static void nextProbablePrime() throws Exception {
int failCount = 0;
BigInteger p1, p2, p3;
p1 = p2 = p3 = ZERO;
// First test nextProbablePrime on the low range starting at zero
for (int i=0; i<primesTo100.length; i++) {
p1 = p1.nextProbablePrime();
if (p1.longValue() != primesTo100[i]) {
System.err.println("low range primes failed");
System.err.println("p1 is "+p1);
System.err.println("expected "+primesTo100[i]);
failCount++;
}
}
// Test nextProbablePrime on a relatively small, known prime sequence
p1 = BigInteger.valueOf(aPrimeSequence[0]);
for (int i=1; i<aPrimeSequence.length; i++) {
p1 = p1.nextProbablePrime();
if (p1.longValue() != aPrimeSequence[i]) {
System.err.println("prime sequence failed");
failCount++;
}
}
// Next, pick some large primes, use nextProbablePrime to find the
// next one, and make sure there are no primes in between
for (int i=0; i<100; i+=10) {
p1 = BigInteger.probablePrime(50 + i, rnd);
p2 = p1.add(ONE);
p3 = p1.nextProbablePrime();
while(p2.compareTo(p3) < 0) {
if (p2.isProbablePrime(100)){
System.err.println("nextProbablePrime failed");
System.err.println("along range "+p1.toString(16));
System.err.println("to "+p3.toString(16));
failCount++;
break;
}
p2 = p2.add(ONE);
}
}
report("nextProbablePrime", failCount);
}
public static void serialize() throws Exception {
int failCount = 0;
String bitPatterns[] = {
"ffffffff00000000ffffffff00000000ffffffff00000000",
"ffffffffffffffffffffffff000000000000000000000000",
"ffffffff0000000000000000000000000000000000000000",
"10000000ffffffffffffffffffffffffffffffffffffffff",
"100000000000000000000000000000000000000000000000",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"-ffffffff00000000ffffffff00000000ffffffff00000000",
"-ffffffffffffffffffffffff000000000000000000000000",
"-ffffffff0000000000000000000000000000000000000000",
"-10000000ffffffffffffffffffffffffffffffffffffffff",
"-100000000000000000000000000000000000000000000000",
"-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
};
for(int i = 0; i < bitPatterns.length; i++) {
BigInteger b1 = new BigInteger(bitPatterns[i], 16);
File f = new File("serialtest");
FileOutputStream fos = new FileOutputStream(f);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(b1);
oos.flush();
oos.close();
FileInputStream fis = new FileInputStream(f);
ObjectInputStream ois = new ObjectInputStream(fis);
BigInteger b2 = (BigInteger)ois.readObject();
if (!b1.equals(b2) ||
!b1.equals(b1.or(b2))) {
failCount++;
System.err.println("Serialized failed for hex " +
b1.toString(16));
}
f.delete();
}
for(int i=0; i<10; i++) {
BigInteger b1 = fetchNumber(rnd.nextInt(100));
File f = new File("serialtest");
FileOutputStream fos = new FileOutputStream(f);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(b1);
oos.flush();
oos.close();
FileInputStream fis = new FileInputStream(f);
ObjectInputStream ois = new ObjectInputStream(fis);
BigInteger b2 = (BigInteger)ois.readObject();
if (!b1.equals(b2) ||
!b1.equals(b1.or(b2)))
failCount++;
f.delete();
}
report("Serialize", failCount);
}
/**
* Main to interpret arguments and run several tests.
*
* Up to three arguments may be given to specify the size of BigIntegers
* used for call parameters 1, 2, and 3. The size is interpreted as
* the maximum number of decimal digits that the parameters will have.
*
*/
public static void main(String[] args) throws Exception {
if (args.length >0)
order1 = (int)((Integer.parseInt(args[0]))* 3.333);
if (args.length >1)
order2 = (int)((Integer.parseInt(args[1]))* 3.333);
if (args.length >2)
order3 = (int)((Integer.parseInt(args[2]))* 3.333);
prime();
nextProbablePrime();
arithmetic();
divideAndRemainder();
pow();
bitCount();
bitLength();
bitOps();
bitwise();
shift();
byteArrayConv();
modInv();
modExp();
modExp2();
stringConv();
serialize();
if (failure)
throw new RuntimeException("Failure in BigIntegerTest.");
}
/*
* Get a random or boundary-case number. This is designed to provide
* a lot of numbers that will find failure points, such as max sized
* numbers, empty BigIntegers, etc.
*
* If order is less than 2, order is changed to 2.
*/
private static BigInteger fetchNumber(int order) {
boolean negative = rnd.nextBoolean();
int numType = rnd.nextInt(6);
BigInteger result = null;
if (order < 2) order = 2;
switch (numType) {
case 0: // Empty
result = BigInteger.ZERO;
break;
case 1: // One
result = BigInteger.ONE;
break;
case 2: // All bits set in number
int numBytes = (order+7)/8;
byte[] fullBits = new byte[numBytes];
for(int i=0; i<numBytes; i++)
fullBits[i] = (byte)0xff;
int excessBits = 8*numBytes - order;
fullBits[0] &= (1 << (8-excessBits)) - 1;
result = new BigInteger(1, fullBits);
break;
case 3: // One bit in number
result = BigInteger.ONE.shiftLeft(rnd.nextInt(order));
break;
case 4: // Random bit density
int iterations = rnd.nextInt(order-1);
result = BigInteger.ONE.shiftLeft(rnd.nextInt(order));
for(int i=0; i<iterations; i++) {
BigInteger temp = BigInteger.ONE.shiftLeft(
rnd.nextInt(order));
result = result.or(temp);
}
break;
default: // random bits
result = new BigInteger(order, rnd);
}
if (negative)
result = result.negate();
return result;
}
static void report(String testName, int failCount) {
System.err.println(testName+": " +
(failCount==0 ? "Passed":"Failed("+failCount+")"));
if (failCount > 0)
failure = true;
}
}
/*
* Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
* @bug 4181191
* @summary test BigInteger modPow method
*/
import java.math.BigInteger;
import java.util.Random;
public class ModPow {
public static void main(String[] args) {
Random rnd = new Random(1234);
for (int i=0; i<2000; i++) {
BigInteger m = new BigInteger(800, rnd);
BigInteger base = new BigInteger(16, rnd);
if (rnd.nextInt() % 1 == 0)
base = base.negate();
BigInteger exp = new BigInteger(8, rnd);
BigInteger z = base.modPow(exp, m);
BigInteger w = base.pow(exp.intValue()).mod(m);
if (!z.equals(w)){
System.err.println(base +" ** " + exp + " mod "+ m);
System.err.println("modPow : " + z);
System.err.println("pow.mod: " + w);
throw new RuntimeException("BigInteger modPow failure.");
}
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4891312
* @summary verify that modPow() not broken by the special case for 65537
* @author Andreas Sterbenz
*/
import java.math.BigInteger;
import java.util.*;
import java.security.*;
import java.security.spec.*;
public class ModPow65537 {
public static void main(String[] args) throws Exception {
// SunRsaSign uses BigInteger internally
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunRsaSign");
kpg.initialize(new RSAKeyGenParameterSpec(512, BigInteger.valueOf(65537)));
KeyPair kp = kpg.generateKeyPair();
testSigning(kp);
kpg.initialize(new RSAKeyGenParameterSpec(512, BigInteger.valueOf(65539)));
kp = kpg.generateKeyPair();
testSigning(kp);
kpg.initialize(new RSAKeyGenParameterSpec(512, BigInteger.valueOf(3)));
kp = kpg.generateKeyPair();
testSigning(kp);
// basic known answer test
BigInteger base = new BigInteger("19058071224156864789844466979330892664777520457048234786139035643344145635582");
BigInteger mod = new BigInteger("75554098474976067521257305210610421240510163914613117319380559667371251381587");
BigInteger exp1 = BigInteger.valueOf(65537);
BigInteger exp2 = BigInteger.valueOf(75537);
BigInteger exp3 = new BigInteger("13456870775607312149");
BigInteger res1 = new BigInteger("5770048609366563851320890693196148833634112303472168971638730461010114147506");
BigInteger res2 = new BigInteger("63446979364051087123350579021875958137036620431381329472348116892915461751531");
BigInteger res3 = new BigInteger("39016891919893878823999350081191675846357272199067075794096200770872982089502");
if (base.modPow(exp1, mod).equals(res1) == false) {
throw new Exception("Error using " + exp1);
}
if (base.modPow(exp2, mod).equals(res2) == false) {
throw new Exception("Error using " + exp2);
}
if (base.modPow(exp3, mod).equals(res3) == false) {
throw new Exception("Error using " + exp3);
}
System.out.println("Passed");
}
private static void testSigning(KeyPair kp) throws Exception {
System.out.println(kp.getPublic());
byte[] data = new byte[1024];
new Random().nextBytes(data);
Signature sig = Signature.getInstance("SHA1withRSA", "SunRsaSign");
sig.initSign(kp.getPrivate());
sig.update(data);
byte[] sigBytes = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(data);
if (sig.verify(sigBytes) == false) {
throw new Exception("signature verification failed");
}
System.out.println("OK");
}
}
/*
* Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
@bug 4098742
@summary Test biginteger modpow method
@author Michael McCloskey
@run main/othervm ModPowPowersof2
*/
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.IOException;
/**
* This class tests to see if using modPow on a power
* of two crashes the vm
*
*/
public class ModPowPowersof2 {
public static void main(String args[]) throws Exception {
// Construct a command that runs the test in other vm
String[] command = new String[4];
int n = 0;
command[n++] = System.getProperty("java.home") + File.separator +
"bin" + File.separator + "java";
if (System.getProperty("java.class.path") != null) {
command[n++] = "-classpath";
command[n++] = System.getProperty("java.class.path");
}
command[n++] = "ModPowPowersof2$ModTester";
// Exec another vm to run test in
Process p = null;
p = Runtime.getRuntime().exec(command);
// Read the result to determine if test failed
BufferedReader in = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String s;
s = in.readLine();
if (s == null)
throw new RuntimeException("ModPow causes vm crash");
}
public static class ModTester {
public static void main(String [] args) {
BigInteger two = BigInteger.valueOf(2);
BigInteger four = BigInteger.valueOf(4);
two.modPow(two, BigInteger.valueOf(4));
two.modPow(two, BigInteger.valueOf(8));
two.modPow(four, BigInteger.valueOf(8));
System.out.println("success");
}
}
}
/*
* Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6365176
* @summary Get NullPointerExceptions when expected
* @author Joseph D. Darcy
*/
import java.math.*;
import static java.math.BigInteger.*;
public class OperatorNpeTests {
public static void main(String... argv) {
BigInteger[] specialValues = {ZERO, ONE, TEN};
for (BigInteger bd : specialValues) {
BigInteger result;
try {
result = bd.multiply(null);
throw new RuntimeException("Instead of NPE got " + result);
} catch (NullPointerException npe) {
; // Expected
}
try {
result = bd.divide(null);
throw new RuntimeException("Instead of NPE got " + result);
} catch (NullPointerException npe) {
; // Expected
}
try {
result = bd.add(null);
throw new RuntimeException("Instead of NPE got " + result);
} catch (NullPointerException npe) {
; // Expected
}
try {
result = bd.subtract(null);
throw new RuntimeException("Instead of NPE got " + result);
} catch (NullPointerException npe) {
; // Expected
}
}
}
}
/*
* Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4654323
* @summary Tests functionality of isProbablePrime(Integer.MAX_VALUE)
*/
import java.math.*;
public class ProbablePrime {
public static void main(String [] argv) {
BigInteger num = new BigInteger("4");
int certainties[] = {-1, 0, 1, 2, 100, Integer.MAX_VALUE-1,
Integer.MAX_VALUE};
boolean expectations[] = {true, true, false, false, false,
false, false};
for(int i = 0; i < certainties.length; i++) {
boolean b;
if((b=num.isProbablePrime(certainties[i])) !=
expectations[i])
throw new RuntimeException("Unexpected answer " + b +
" for certainty " +
certainties[i]);
}
}
}
/*
* Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4489146 5017980
* @summary tests String constructors of BigInteger
* @author Joseph D. Darcy
*/
import java.math.*;
public class StringConstructor {
public static void main(String [] argv) {
// Good strings
constructWithoutError("0", 0L);
constructWithoutError("000000000000000000", 0L);
constructWithoutError("1", 1L);
constructWithoutError("-1", -1L);
constructWithoutError("+1", +1L);
constructWithoutError( "123456789123456789", 123456789123456789L);
constructWithoutError("+123456789123456789", 123456789123456789L);
constructWithoutError("-123456789123456789", -123456789123456789L);
constructWithoutError(Integer.toString(Integer.MIN_VALUE),
(long)Integer.MIN_VALUE);
constructWithoutError(Integer.toString(Integer.MAX_VALUE),
(long)Integer.MAX_VALUE);
constructWithoutError(Long.toString(Long.MIN_VALUE),
Long.MIN_VALUE);
constructWithoutError(Long.toString(Long.MAX_VALUE),
Long.MAX_VALUE);
// Bad strings
constructWithError("");
constructWithError("-");
constructWithError("+");
constructWithError("--");
constructWithError("++");
constructWithError("-000-0");
constructWithError("+000+0");
constructWithError("+000-0");
constructWithError("--1234567890");
constructWithError("++1234567890");
constructWithError("-0-12345678");
constructWithError("+0+12345678");
constructWithError("--12345678-12345678-12345678");
constructWithError("++12345678+12345678+12345678");
constructWithError("12345-");
constructWithError("12345+");
}
// this method adapted from ../BigDecimal/StringConstructor.java
private static void constructWithError(String badString) {
try {
BigInteger bi = new BigInteger(badString);
throw new RuntimeException(badString + " accepted");
} catch(NumberFormatException e) {
}
}
private static void constructWithoutError(String goodString, long value) {
BigInteger bi = new BigInteger(goodString);
if(bi.longValue() != value) {
System.err.printf("From ``%s'' expected %d, got %s.\n", goodString, value, bi);
throw new RuntimeException();
}
}
}
/*
* Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4040456
* @summary Test biginteger constructor with i18n string
*/
import java.math.*;
/**
* This class tests to see if creating a biginteger with an
* unicode japanese zero and one succeeds
*
*/
public class UnicodeConstructor {
public static void main(String args[]) {
try {
// the code for japanese zero
BigInteger b1 = new BigInteger("\uff10");
System.err.println(b1.toString());
// Japanese 1010
BigInteger b2 = new BigInteger("\uff11\uff10\uff11\uff10");
System.err.println(b2.toString());
}
catch (ArrayIndexOutOfBoundsException e) {
throw new RuntimeException(
"BigInteger is not accepting unicode initializers.");
}
}
}
/*
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 4851776 4891522 4905335
* @summary Basic tests for the RoundingMode class.
* @author Joseph D. Darcy
* @compile -source 1.5 RoundingModeTests.java
* @run main RoundingModeTests
*/
import java.math.RoundingMode;
import java.math.BigDecimal;
public class RoundingModeTests {
public static void main(String [] argv) {
// For each member of the family, make sure
// rm == valueOf(rm.toString())
for(RoundingMode rm: RoundingMode.values()) {
if (rm != RoundingMode.valueOf(rm.toString())) {
throw new RuntimeException("Bad roundtrip conversion of " +
rm.toString());
}
}
// Test that mapping of old integers to new values is correct
if (RoundingMode.valueOf(BigDecimal.ROUND_CEILING) !=
RoundingMode.CEILING) {
throw new RuntimeException("Bad mapping for ROUND_CEILING");
}
if (RoundingMode.valueOf(BigDecimal.ROUND_DOWN) !=
RoundingMode.DOWN) {
throw new RuntimeException("Bad mapping for ROUND_DOWN");
}
if (RoundingMode.valueOf(BigDecimal.ROUND_FLOOR) !=
RoundingMode.FLOOR) {
throw new RuntimeException("Bad mapping for ROUND_FLOOR");
}
if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_DOWN) !=
RoundingMode.HALF_DOWN) {
throw new RuntimeException("Bad mapping for ROUND_HALF_DOWN");
}
if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_EVEN) !=
RoundingMode.HALF_EVEN) {
throw new RuntimeException("Bad mapping for ROUND_HALF_EVEN");
}
if (RoundingMode.valueOf(BigDecimal.ROUND_HALF_UP) !=
RoundingMode.HALF_UP) {
throw new RuntimeException("Bad mapping for ROUND_HALF_UP");
}
if (RoundingMode.valueOf(BigDecimal.ROUND_UNNECESSARY) !=
RoundingMode.UNNECESSARY) {
throw new RuntimeException("Bad mapping for ROUND_UNNECESARY");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册