double.java
来自「gcc3.2.1源代码」· Java 代码 · 共 529 行 · 第 1/2 页
JAVA
529 行
/* Double.java -- object wrapper for double primitive Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version. GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING. If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library. Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule. An independent module is a module which is not derived fromor based on this library. If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so. If you do not wish to do so, delete thisexception statement from your version. */package java.lang;import gnu.classpath.Configuration;/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 * "The Java Language Specification", ISBN 0-201-63451-1 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com. * Status: Believed complete and correct. *//** * Instances of class <code>Double</code> represent primitive * <code>double</code> values. * * Additionally, this class provides various helper functions and variables * related to doubles. * * @author Paul Fisher * @author Andrew Haley <aph@cygnus.com> * @since JDK 1.0 */public final class Double extends Number implements Comparable{ /** * The minimum positive value a <code>double</code> may represent * is 5e-324. */ public static final double MIN_VALUE = 5e-324; /** * The maximum positive value a <code>double</code> may represent * is 1.7976931348623157e+308. */ public static final double MAX_VALUE = 1.7976931348623157e+308; /** * The value of a double representation -1.0/0.0, negative * infinity. */ public static final double NEGATIVE_INFINITY = -1.0d/0.0d; /** * The value of a double representing 1.0/0.0, positive infinity. */ public static final double POSITIVE_INFINITY = 1.0d/0.0d; /** * All IEEE 754 values of NaN have the same value in Java. */ public static final double NaN = 0.0d/0.0d; /** * The primitive type <code>double</code> is represented by this * <code>Class</code> object. */ public static final Class TYPE = VMClassLoader.getPrimitiveClass('D'); /** * The immutable value of this Double. */ private final double value; private static final long serialVersionUID = -9172774392245257468L; /** * Load native routines necessary for this class. */ static { if (Configuration.INIT_LOAD_LIBRARY) { System.loadLibrary ("javalang"); initIDs (); } } /** * Create a <code>Double</code> from the primitive <code>double</code> * specified. * * @param value the <code>double</code> argument */ public Double (double value) { this.value = value; } /** * Create a <code>Double</code> from the specified * <code>String</code>. * * This method calls <code>Double.parseDouble()</code>. * * @exception NumberFormatException when the <code>String</code> cannot * be parsed into a <code>Float</code>. * @param s the <code>String</code> to convert * @see #parseDouble(java.lang.String) */ public Double (String s) throws NumberFormatException { value = parseDouble (s); } /** * Convert the <code>double</code> value of this <code>Double</code> * to a <code>String</code>. This method calls * <code>Double.toString(double)</code> to do its dirty work. * * @return the <code>String</code> representation of this <code>Double</code>. * @see #toString(double) */ public String toString () { return toString (value); } /** * If the <code>Object</code> is not <code>null</code>, is an * <code>instanceof</code> <code>Double</code>, and represents * the same primitive <code>double</code> value return * <code>true</code>. Otherwise <code>false</code> is returned. * <p> * Note that there are two differences between <code>==</code> and * <code>equals()</code>. <code>0.0d == -0.0d</code> returns <code>true</code> * but <code>new Double(0.0d).equals(new Double(-0.0d))</code> returns * <code>false</code>. And <code>Double.NaN == Double.NaN</code> returns * <code>false</code>, but * <code>new Double(Double.NaN).equals(new Double(Double.NaN))</code> returns * <code>true</code>. * * @param obj the object to compare to * @return whether the objects are semantically equal. */ public boolean equals (Object obj) { if (!(obj instanceof Double)) return false; double d = ((Double) obj).value; // GCJ LOCAL: this implementation is probably faster than // Classpath's, especially once we inline doubleToLongBits. return doubleToLongBits (value) == doubleToLongBits (d); // END GCJ LOCAL } /** * The hashcode is the value of the expression: <br> * <br> * <code>(int)(v^(v>>>32))</code><br> * <br> * where v is defined by: <br> * <code>long v = Double.doubleToLongBits(this.longValue());</code><br> */ public int hashCode () { long v = doubleToLongBits (value); return (int) (v ^ (v >>> 32)); } /** * Return the value of this <code>Double</code> when cast to an * <code>int</code>. */ public int intValue () { return (int) value; } /** * Return the value of this <code>Double</code> when cast to a * <code>long</code>. */ public long longValue () { return (long) value; } /** * Return the value of this <code>Double</code> when cast to a * <code>float</code>. */ public float floatValue () { return (float) value; } /** * Return the primitive <code>double</code> value represented by this * <code>Double</code>. */ public double doubleValue () { return value; } /** * Return the result of calling <code>new Double(java.lang.String)</code>. * * @param s the <code>String</code> to convert to a <code>Double</code>. * @return a new <code>Double</code> representing the <code>String</code>'s * numeric value. * * @exception NullPointerException thrown if <code>String</code> is * <code>null</code>. * @exception NumberFormatException thrown if <code>String</code> cannot * be parsed as a <code>double</code>. * @see #Double(java.lang.String) * @see #parseDouble(java.lang.String) */ public static Double valueOf (String s) throws NumberFormatException { return new Double (s); } /** * Return <code>true</code> if the value of this <code>Double</code> * is the same as <code>NaN</code>, otherwise return <code>false</code>. * @return whether this <code>Double</code> is <code>NaN</code>. */ public boolean isNaN () { return isNaN (value); } /** * Return <code>true</code> if the <code>double</code> has the same
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?