ParseDouble.java revision 4018
3261N/A * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. 2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @bug 4160406 4705734 4707389 4826774 4895911 4421494 7021568 0N/A * @summary Test for Double.parseDouble method and acceptance regex 0N/A // Make sure intermediate white space is not deleted. 0N/A // Control characters in the interior of a string are not legal 0N/A // NaN and infinity can't have trailing type suffices or exponents 0N/A // Non-ASCII digits are not recognized 0N/A "\u0661e\u0661",
// 1e1 in Arabic-Indic digits 0N/A "\u06F1e\u06F1",
// 1e1 in Extended Arabic-Indic digits 0N/A "\u0967e\u0967",
// 1e1 in Devanagari digits 0N/A // JCK test lex03592m3 0N/A // JCK test lex03592m4 0N/A // JCK test lex03592m5 0N/A // JCK test lex03592m6 0N/A // JCK test lex03592m7 0N/A // JCK test lex03592m8 0N/A // JCK test lex03592m9 0N/A // JCK test lex03593m10 0N/A // JCK test lex03593m11 0N/A // JCK test lex03593m12 0N/A // JCK test lex03593m14 0N/A // JCK test lex03593m15 0N/A // JCK test lex03593m16 0N/A // JCK test lex03593m18 0N/A // JCK test lex03593m20 0N/A // JCK test lex03593m21 0N/A // JCK test lex03593m22 0N/A // JCK test lex03593m24 0N/A // JCK test lex03593m25 // Bad hexadecimal-style strings // Must have hex specifier // Need an explicit fully-formed exponent // Exponent must be in decimal // Exponent separated by "p" "2147483647",
// Integer.MAX_VALUE "-2147483648",
// Integer.MIN_VALUE "9007199254740992",
// 2^53 "-9007199254740992",
// -2^53 "9223372036854775808",
// Long.MAX_VALUE "-9223372036854775809",
// Long.MIN_VALUE // Culled from JCK test lex03591m1 "000000000000000000000000001.F",
"1.00000000000000000000000000e-2F",
// Culled from JCK test lex03592m2 // Culled from JCK test lex03594m31 -- unicode escapes "\u0035\u0031\u0034\u0039\u0032\u0033\u0036\u0037\u0038\u0030.1102E-209D",
"1290873\u002E12301e100",
// Culled from JCK test lex03595m1 // Culled from JCK test lex03691m1 // Vary capitalization of separators. // Try different significand combinations "1.7976931348623157E308",
// Double.MAX_VALUE "4.9e-324",
// Double.MIN_VALUE "2.2250738585072014e-308",
// Double.MIN_NORMAL "2.2250738585072012e-308",
// near Double.MIN_NORMAL * 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 "good string `" +
input[i] +
"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. * The regex below is taken from the JavaDoc for // an exponent is 'e' or 'E' followed by an optionally // signed decimal integer. (
"[\\x00-\\x20]*"+
// Optional leading "whitespace" "[+-]?(" +
// Optional sign character "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 ExponentPart_opt FloatTypeSuffix_opt // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt ")[pP][+-]?" +
Digits +
"))" +
"[\\x00-\\x20]*");
// Optional trailing "whitespace" * For each subnormal power of two, test at boundaries of * region that should convert to that value. // An ulp is the same for all subnormal values // Test subnormal powers of two for(
int i = -
1074; i <= -
1022; i++) {
* The region [d - ulp/2, d + ulp/2] should round to d. final double expected =
0x0.
0000008000001p-
1022;
double sum =
0.0;
// Prevent conversion from being optimized away String decimal =
"6.631236871469758276785396630275967243399099947355303144249971758736286630139265439618068200788048744105960420552601852889715006376325666595539603330361800519107591783233358492337208057849499360899425128640718856616503093444922854759159988160304439909868291973931426625698663157749836252274523485312442358651207051292453083278116143932569727918709786004497872322193856150225415211997283078496319412124640111777216148110752815101775295719811974338451936095907419622417538473679495148632480391435931767981122396703443803335529756003353209830071832230689201383015598792184172909927924176339315507402234836120730914783168400715462440053817592702766213559042115986763819482654128770595766806872783349146967171293949598850675682115696218943412532098591327667236328125E-316";
for(
int i =
0; i <=
12_000; i++) {