1 /*
2 * Copyright 1994-2006 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
348 * <dd>{@code P}
349 * </dl>
350 *
351 * </blockquote>
352 *
353 * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
354 * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
355 * <i>FloatTypeSuffix</i> are as defined in the lexical structure
356 * sections of the <a
357 * href="http://java.sun.com/docs/books/jls/html/">Java Language
358 * Specification</a>. If {@code s} does not have the form of
359 * a <i>FloatValue</i>, then a {@code NumberFormatException}
360 * is thrown. Otherwise, {@code s} is regarded as
361 * representing an exact decimal value in the usual
362 * "computerized scientific notation" or as an exact
363 * hexadecimal value; this exact numerical value is then
364 * conceptually converted to an "infinitely precise"
365 * binary value that is then rounded to type {@code float}
366 * by the usual round-to-nearest rule of IEEE 754 floating-point
367 * arithmetic, which includes preserving the sign of a zero
368 * value. Finally, a {@code Float} object representing this
369 * {@code float} value is returned.
370 *
371 * <p>To interpret localized string representations of a
372 * floating-point value, use subclasses of {@link
373 * java.text.NumberFormat}.
374 *
375 * <p>Note that trailing format specifiers, specifiers that
376 * determine the type of a floating-point literal
377 * ({@code 1.0f} is a {@code float} value;
378 * {@code 1.0d} is a {@code double} value), do
379 * <em>not</em> influence the results of this method. In other
380 * words, the numerical value of the input string is converted
381 * directly to the target floating-point type. In general, the
382 * two-step sequence of conversions, string to {@code double}
383 * followed by {@code double} to {@code float}, is
384 * <em>not</em> equivalent to converting a string directly to
385 * {@code float}. For example, if first converted to an
386 * intermediate {@code double} and then to
387 * {@code float}, the string<br>
388 * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
389 * results in the {@code float} value
390 * {@code 1.0000002f}; if the string is converted directly to
|
1 /*
2 * Copyright 1994-2009 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
348 * <dd>{@code P}
349 * </dl>
350 *
351 * </blockquote>
352 *
353 * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
354 * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
355 * <i>FloatTypeSuffix</i> are as defined in the lexical structure
356 * sections of the <a
357 * href="http://java.sun.com/docs/books/jls/html/">Java Language
358 * Specification</a>. If {@code s} does not have the form of
359 * a <i>FloatValue</i>, then a {@code NumberFormatException}
360 * is thrown. Otherwise, {@code s} is regarded as
361 * representing an exact decimal value in the usual
362 * "computerized scientific notation" or as an exact
363 * hexadecimal value; this exact numerical value is then
364 * conceptually converted to an "infinitely precise"
365 * binary value that is then rounded to type {@code float}
366 * by the usual round-to-nearest rule of IEEE 754 floating-point
367 * arithmetic, which includes preserving the sign of a zero
368 * value.
369 *
370 * Note that the round-to-nearest rule also implies overflow and
371 * underflow behaviour; if the exact value of {@code s} is large
372 * enough in magnitude (greater than or equal to ({@link
373 * #MAX_VALUE} + {@link Math#ulp(float) ulp(MAX_VALUE)}/2),
374 * rounding to {@code float} will result in an infinity and if the
375 * exact value of {@code s} is small enough in magnitude (less
376 * than or equal to {@link #MIN_VALUE}/2), rounding to float will
377 * result in a zero.
378 *
379 * Finally, after rounding a {@code Float} object representing
380 * this {@code float} value is returned.
381 *
382 * <p>To interpret localized string representations of a
383 * floating-point value, use subclasses of {@link
384 * java.text.NumberFormat}.
385 *
386 * <p>Note that trailing format specifiers, specifiers that
387 * determine the type of a floating-point literal
388 * ({@code 1.0f} is a {@code float} value;
389 * {@code 1.0d} is a {@code double} value), do
390 * <em>not</em> influence the results of this method. In other
391 * words, the numerical value of the input string is converted
392 * directly to the target floating-point type. In general, the
393 * two-step sequence of conversions, string to {@code double}
394 * followed by {@code double} to {@code float}, is
395 * <em>not</em> equivalent to converting a string directly to
396 * {@code float}. For example, if first converted to an
397 * intermediate {@code double} and then to
398 * {@code float}, the string<br>
399 * {@code "1.00000017881393421514957253748434595763683319091796875001d"}<br>
400 * results in the {@code float} value
401 * {@code 1.0000002f}; if the string is converted directly to
|