ParseDouble.java revision 4124
3909N/A * Copyright (c) 2001, 2011, 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 4124N/A * @bug 4160406 4705734 4707389 4826774 4895911 4421494 7021568 7039369 809N/A * @summary Test for Double.parseDouble method and acceptance regex 809N/A // Make sure intermediate white space is not deleted. 809N/A // Control characters in the interior of a string are not legal 809N/A // NaN and infinity can't have trailing type suffices or exponents 809N/A // Non-ASCII digits are not recognized 809N/A "\u0661e\u0661",
// 1e1 in Arabic-Indic digits 809N/A "\u06F1e\u06F1",
// 1e1 in Extended Arabic-Indic digits 809N/A "\u0967e\u0967",
// 1e1 in Devanagari digits 809N/A // JCK test lex03593m10 809N/A // JCK test lex03593m11 809N/A // JCK test lex03593m12 809N/A // JCK test lex03593m14 809N/A // JCK test lex03593m15 809N/A // JCK test lex03593m16 809N/A // JCK test lex03593m18 809N/A // JCK test lex03593m20 809N/A // JCK test lex03593m21 809N/A // JCK test lex03593m22 809N/A // JCK test lex03593m24 809N/A // JCK test lex03593m25 809N/A // JCK test lex03593m26 809N/A // JCK test lex03593m27 809N/A // JCK test lex03593m28 809N/A // JCK test lex03593m29 809N/A // JCK test lex03593m30 809N/A // Bad hexadecimal-style strings 809N/A // Must have hex specifier 809N/A // Need an explicit fully-formed exponent 809N/A // Exponent must be in decimal 809N/A // Exponent separated by "p" 809N/A "2147483647",
// Integer.MAX_VALUE 809N/A "-2147483648",
// Integer.MIN_VALUE 809N/A "9007199254740992",
// 2^53 809N/A "-9007199254740992",
// -2^53 809N/A "9223372036854775808",
// Long.MAX_VALUE 809N/A "-9223372036854775808",
809N/A "-9223372036854775809",
// Long.MIN_VALUE 809N/A "-9223372036854775810",
809N/A // Culled from JCK test lex03591m1 809N/A "000000000000000000000000001.F",
809N/A "1.00000000000000000000000000e-2F",
809N/A // Culled from JCK test lex03592m2 809N/A "122112217090.0E+100D",
809N/A // Culled from JCK test lex03594m31 -- unicode escapes 809N/A "\u0035\u0031\u0034\u0039\u0032\u0033\u0036\u0037\u0038\u0030.1102E-209D",
809N/A "1290873\u002E12301e100",
809N/A // Culled from JCK test lex03595m1 809N/A // Culled from JCK test lex03691m1 809N/A // Vary capitalization of separators. 809N/A // Try different significand combinations 3502N/A "1.7976931348623157E308",
// Double.MAX_VALUE 3502N/A "4.9e-324",
// Double.MIN_VALUE 3502N/A "2.2250738585072014e-308",
// Double.MIN_NORMAL 3502N/A "2.2250738585072012e-308",
// near Double.MIN_NORMAL 809N/A * Throws an exception if <code>Input</code> is 809N/A * <code>exceptionalInput</code> and {@link Double.parseDouble 809N/A * parseDouble} does <em>not</em> throw an exception or if 809N/A * <code>Input</code> is not <code>exceptionalInput</code> and 809N/A * <code>parseDouble</code> throws an exception. This method does 809N/A * not attempt to test whether the string is converted to the 809N/A * proper value; just whether the input is accepted appropriately 809N/A * Throws an exception if <code>Input</code> is 809N/A * <code>exceptionalInput</code> and the regular expression 809N/A * matches one of the strings or if <code>Input</code> is not 809N/A * <code>exceptionalInput</code> and the regular expression fails 809N/A * to match an input string. 809N/A * The regex below is taken from the JavaDoc for 809N/A // an exponent is 'e' or 'E' followed by an optionally 809N/A // signed decimal integer. 809N/A (
"[\\x00-\\x20]*"+
// Optional leading "whitespace" 809N/A "[+-]?(" +
// Optional sign character 809N/A "NaN|" +
// "NaN" string 809N/A "Infinity|" +
// "Infinity" string 809N/A // A floating-point string representing a finite positive 809N/A // number without a leading sign has at most five basic pieces: 809N/A // Digits . Digits ExponentPart FloatTypeSuffix 809N/A // Since this method allows integer-only strings as input 809N/A // in addition to strings of floating-point literals, the 809N/A // two sub-patterns below are simplifications of the grammar 809N/A // productions from the Java Language Specification, 2nd 809N/A // edition, section 3.10.2. 809N/A // A decimal floating-point string representing a finite positive 809N/A // number without a leading sign has at most five basic pieces: 809N/A // Digits . Digits ExponentPart FloatTypeSuffix 809N/A // Since this method allows integer-only strings as input 809N/A // in addition to strings of floating-point literals, the 809N/A // two sub-patterns below are simplifications of the grammar 809N/A // productions from the Java Language Specification, 2nd 809N/A // edition, section 3.10.2. 809N/A // Digits ._opt Digits_opt ExponentPart_opt FloatTypeSuffix_opt 809N/A // . Digits ExponentPart_opt FloatTypeSuffix_opt 809N/A // 0[xX] HexDigits ._opt BinaryExponent FloatTypeSuffix_opt 809N/A // 0[xX] HexDigits_opt . HexDigits BinaryExponent FloatTypeSuffix_opt 809N/A "[\\x00-\\x20]*");
// Optional trailing "whitespace" 3502N/A * For each subnormal power of two, test at boundaries of 3502N/A * region that should convert to that value. 3502N/A // An ulp is the same for all subnormal values 3502N/A // Test subnormal powers of two 3502N/A for(
int i = -
1074; i <= -
1022; i++) {
3502N/A * The region [d - ulp/2, d + ulp/2] should round to d. 4018N/A double sum =
0.0;
// Prevent conversion from being optimized away 4018N/A String decimal =
"6.631236871469758276785396630275967243399099947355303144249971758736286630139265439618068200788048744105960420552601852889715006376325666595539603330361800519107591783233358492337208057849499360899425128640718856616503093444922854759159988160304439909868291973931426625698663157749836252274523485312442358651207051292453083278116143932569727918709786004497872322193856150225415211997283078496319412124640111777216148110752815101775295719811974338451936095907419622417538473679495148632480391435931767981122396703443803335529756003353209830071832230689201383015598792184172909927924176339315507402234836120730914783168400715462440053817592702766213559042115986763819482654128770595766806872783349146967171293949598850675682115696218943412532098591327667236328125E-316";