提交 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();
}
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册