src/share/classes/java/lang/Double.java

Print this page


   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


 387      * <dd>{@code P}
 388      * </dl>
 389      *
 390      * </blockquote>
 391      *
 392      * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 393      * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 394      * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 395      * sections of the <a
 396      * href="http://java.sun.com/docs/books/jls/html/">Java Language
 397      * Specification</a>. If {@code s} does not have the form of
 398      * a <i>FloatValue</i>, then a {@code NumberFormatException}
 399      * is thrown. Otherwise, {@code s} is regarded as
 400      * representing an exact decimal value in the usual
 401      * "computerized scientific notation" or as an exact
 402      * hexadecimal value; this exact numerical value is then
 403      * conceptually converted to an "infinitely precise"
 404      * binary value that is then rounded to type {@code double}
 405      * by the usual round-to-nearest rule of IEEE 754 floating-point
 406      * arithmetic, which includes preserving the sign of a zero
 407      * value. Finally, a {@code Double} object representing this
 408      * {@code double} value is returned.
 409      *












 410      * <p> To interpret localized string representations of a
 411      * floating-point value, use subclasses of {@link
 412      * java.text.NumberFormat}.
 413      *
 414      * <p>Note that trailing format specifiers, specifiers that
 415      * determine the type of a floating-point literal
 416      * ({@code 1.0f} is a {@code float} value;
 417      * {@code 1.0d} is a {@code double} value), do
 418      * <em>not</em> influence the results of this method.  In other
 419      * words, the numerical value of the input string is converted
 420      * directly to the target floating-point type.  The two-step
 421      * sequence of conversions, string to {@code float} followed
 422      * by {@code float} to {@code double}, is <em>not</em>
 423      * equivalent to converting a string directly to
 424      * {@code double}. For example, the {@code float}
 425      * literal {@code 0.1f} is equal to the {@code double}
 426      * value {@code 0.10000000149011612}; the {@code float}
 427      * literal {@code 0.1f} represents a different numerical
 428      * value than the {@code double} literal
 429      * {@code 0.1}. (The numerical value 0.1 cannot be exactly


   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


 387      * <dd>{@code P}
 388      * </dl>
 389      *
 390      * </blockquote>
 391      *
 392      * where <i>Sign</i>, <i>FloatingPointLiteral</i>,
 393      * <i>HexNumeral</i>, <i>HexDigits</i>, <i>SignedInteger</i> and
 394      * <i>FloatTypeSuffix</i> are as defined in the lexical structure
 395      * sections of the <a
 396      * href="http://java.sun.com/docs/books/jls/html/">Java Language
 397      * Specification</a>. If {@code s} does not have the form of
 398      * a <i>FloatValue</i>, then a {@code NumberFormatException}
 399      * is thrown. Otherwise, {@code s} is regarded as
 400      * representing an exact decimal value in the usual
 401      * "computerized scientific notation" or as an exact
 402      * hexadecimal value; this exact numerical value is then
 403      * conceptually converted to an "infinitely precise"
 404      * binary value that is then rounded to type {@code double}
 405      * by the usual round-to-nearest rule of IEEE 754 floating-point
 406      * arithmetic, which includes preserving the sign of a zero
 407      * value. 

 408      *
 409      * Note that the round-to-nearest rule also implies overflow and
 410      * underflow behaviour; if the exact value of {@code s} is large
 411      * enough in magnitude (greater than or equal to ({@link
 412      * #MAX_VALUE} + {@link Math#ulp(double) ulp(MAX_VALUE)}/2),
 413      * rounding to {@code double} will result in an infinity and if the
 414      * exact value of {@code s} is small enough in magnitude (less
 415      * than or equal to {@link #MIN_VALUE}/2), rounding to float will
 416      * result in a zero.
 417      *
 418      * Finally, after rounding a {@code Double} object representing
 419      * this {@code double} value is returned.
 420      *
 421      * <p> To interpret localized string representations of a
 422      * floating-point value, use subclasses of {@link
 423      * java.text.NumberFormat}.
 424      *
 425      * <p>Note that trailing format specifiers, specifiers that
 426      * determine the type of a floating-point literal
 427      * ({@code 1.0f} is a {@code float} value;
 428      * {@code 1.0d} is a {@code double} value), do
 429      * <em>not</em> influence the results of this method.  In other
 430      * words, the numerical value of the input string is converted
 431      * directly to the target floating-point type.  The two-step
 432      * sequence of conversions, string to {@code float} followed
 433      * by {@code float} to {@code double}, is <em>not</em>
 434      * equivalent to converting a string directly to
 435      * {@code double}. For example, the {@code float}
 436      * literal {@code 0.1f} is equal to the {@code double}
 437      * value {@code 0.10000000149011612}; the {@code float}
 438      * literal {@code 0.1f} represents a different numerical
 439      * value than the {@code double} literal
 440      * {@code 0.1}. (The numerical value 0.1 cannot be exactly