2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. 809N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 809N/A * This code is free software; you can redistribute it and/or modify it 809N/A * under the terms of the GNU General Public License version 2 only, as 809N/A * published by the Free Software Foundation. 809N/A * This code is distributed in the hope that it will be useful, but WITHOUT 809N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 809N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 809N/A * version 2 for more details (a copy is included in the LICENSE file that 809N/A * accompanied this code). 809N/A * You should have received a copy of the GNU General Public License version 809N/A * 2 along with this work; if not, write to the Free Software Foundation, 809N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 809N/A * @summary Numerical tests for hexadecimal inputs to parseDouble, parseFloat 809N/A * @author Joseph D. Darcy 809N/A // Try different combination of letter components 809N/A for(
int i =
0; i <
2; i++) {
809N/A for(
int j =
0; j <
2; j++) {
809N/A for(
int k =
0; k <
2; k++) {
809N/A * Test easy and tricky double rounding cases. 809N/A * A String, double pair 809N/A // Hex strings that convert to three; test basic functionality 809N/A // of significand and exponent shift adjusts along with the 809N/A // no-op of adding leading zeros. These cases don't exercise 809N/A // Test zero significand with large exponents. 809N/A // Test nonzero significand with large exponents. 809N/A // Test significands with different lengths and bit patterns. 809N/A for(
int i =
1; i <=
0xe; i++) {
809N/A // Half-way case between zero and MIN_VALUE rounds down to 809N/A // Slighly more than half-way case between zero and 809N/A // MIN_VALUES rounds up to zero. 809N/A // More subnormal rounding tests 809N/A // Large value and overflow rounding tests 809N/A // Consistency check; double => hexadecimal => double 809N/A // preserves the original value. 809N/A for(
int i =
0; i <
1000; i++) {
809N/A * Verify rounding works the same regardless of how the 809N/A * significand is aligned on input. A useful extension could be 809N/A * to have this sort of test for strings near the overflow 809N/A // baseSignif * 2^baseExp = nextDown(2.0) 809N/A for(
int i =
0; i <
2; i++) {
809N/A for(
long j =
0; j <=
0xfL; j++) {
809N/A for(
long k =
0; k <=
8; k+=
4) {
// k = {0, 4, 8} 809N/A // Calculate when significand should be incremented 809N/A // see table 4.7 in Koren book 809N/A if ( (j >=
8L) &&
// round is 1 809N/A ((j &
0x7L) !=
0 || k !=
0 ) )
// sticky is 1 809N/A if (j >=
8L)
// round is 1 809N/A for(
int m = -
2; m <=
3; m++) {
809N/A // Form equal value string and evaluate it 809N/A * Test tricky float rounding cases. The code which 809N/A * reads in a hex string converts the string to a double value. 809N/A * If a float value is needed, the double value is cast to float. 809N/A * However, the cast be itself not always guaranteed to return the 809N/A * 1. hex string => double can discard a sticky bit which would 809N/A * influence a direct hex string => float conversion. 809N/A * 2. hex string => double => float can have a rounding to double 809N/A * precision which results in a larger float value while a direct 809N/A * hex string => float conversion would not round up. 809N/A * This method includes tests of the latter two possibilities. 809N/A // Target float value hard rouding version 809N/A {
"0x1.000000p0",
"0x1.0000000000001p0"},
809N/A // Try some values that should round up to nextUp(1.0f) 809N/A {
"0x1.000002p0",
"0x1.0000010000001p0"},
809N/A {
"0x1.000002p0",
"0x1.00000100000008p0"},
809N/A {
"0x1.000002p0",
"0x1.0000010000000fp0"},
809N/A {
"0x1.000002p0",
"0x1.00000100000001p0"},
809N/A {
"0x1.000002p0",
"0x1.00000100000000000000000000000000000000001p0"},
809N/A {
"0x1.000002p0",
"0x1.0000010000000fp0"},
809N/A // Potential double rounding cases 809N/A {
"0x1.000002p0",
"0x1.000002fffffffp0"},
809N/A {
"0x1.000002p0",
"0x1.000002fffffff8p0"},
809N/A {
"0x1.000002p0",
"0x1.000002ffffffffp0"},
809N/A {
"0x1.000002p0",
"0x1.000002ffff0ffp0"},
809N/A {
"0x1.000002p0",
"0x1.000002ffff0ff8p0"},
809N/A {
"0x1.000002p0",
"0x1.000002ffff0fffp0"},
809N/A {
"0x1.000000p0",
"0x1.000000fffffffp0"},
809N/A {
"0x1.000000p0",
"0x1.000000fffffff8p0"},
809N/A {
"0x1.000000p0",
"0x1.000000ffffffffp0"},
809N/A {
"0x1.000000p0",
"0x1.000000ffffffep0"},
809N/A {
"0x1.000000p0",
"0x1.000000ffffffe8p0"},
809N/A {
"0x1.000000p0",
"0x1.000000ffffffefp0"},
809N/A // Float subnormal cases 809N/A {
"0x0.000002p-126",
"0x0.0000010000001p-126"},
809N/A {
"0x0.000002p-126",
"0x0.00000100000000000001p-126"},
809N/A {
"0x0.000006p-126",
"0x0.0000050000001p-126"},
809N/A {
"0x0.000006p-126",
"0x0.00000500000000000001p-126"},
809N/A {
"0x0.0p-149",
"0x0.7ffffffffffffffp-149"},
809N/A {
"0x1.0p-148",
"0x1.3ffffffffffffffp-148"},
809N/A {
"0x1.cp-147",
"0x1.bffffffffffffffp-147"},
809N/A {
"0x1.fffffcp-127",
"0x1.fffffdffffffffp-127"},
809N/A "testing hexadecimal floating-point " +