src/share/classes/java/lang/Float.java

Print this page


   1 /*
   2  * Copyright (c) 1994, 2010, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 539      *          {@code false} otherwise.
 540      */
 541     public boolean isInfinite() {
 542         return isInfinite(value);
 543     }
 544 
 545     /**
 546      * Returns a string representation of this {@code Float} object.
 547      * The primitive {@code float} value represented by this object
 548      * is converted to a {@code String} exactly as if by the method
 549      * {@code toString} of one argument.
 550      *
 551      * @return  a {@code String} representation of this object.
 552      * @see java.lang.Float#toString(float)
 553      */
 554     public String toString() {
 555         return Float.toString(value);
 556     }
 557 
 558     /**
 559      * Returns the value of this {@code Float} as a {@code byte} (by
 560      * casting to a {@code byte}).
 561      *
 562      * @return  the {@code float} value represented by this object
 563      *          converted to type {@code byte}

 564      */
 565     public byte byteValue() {
 566         return (byte)value;
 567     }
 568 
 569     /**
 570      * Returns the value of this {@code Float} as a {@code short} (by
 571      * casting to a {@code short}).
 572      *
 573      * @return  the {@code float} value represented by this object
 574      *          converted to type {@code short}

 575      * @since JDK1.1
 576      */
 577     public short shortValue() {
 578         return (short)value;
 579     }
 580 
 581     /**
 582      * Returns the value of this {@code Float} as an {@code int} (by
 583      * casting to type {@code int}).
 584      *
 585      * @return  the {@code float} value represented by this object
 586      *          converted to type {@code int}

 587      */
 588     public int intValue() {
 589         return (int)value;
 590     }
 591 
 592     /**
 593      * Returns value of this {@code Float} as a {@code long} (by
 594      * casting to type {@code long}).
 595      *
 596      * @return  the {@code float} value represented by this object
 597      *          converted to type {@code long}

 598      */
 599     public long longValue() {
 600         return (long)value;
 601     }
 602 
 603     /**
 604      * Returns the {@code float} value of this {@code Float} object.
 605      *
 606      * @return the {@code float} value represented by this object
 607      */
 608     public float floatValue() {
 609         return value;
 610     }
 611 
 612     /**
 613      * Returns the {@code double} value of this {@code Float} object.

 614      *
 615      * @return the {@code float} value represented by this
 616      *         object is converted to type {@code double} and the
 617      *         result of the conversion is returned.
 618      */
 619     public double doubleValue() {
 620         return (double)value;
 621     }
 622 
 623     /**
 624      * Returns a hash code for this {@code Float} object. The
 625      * result is the integer bit representation, exactly as produced
 626      * by the method {@link #floatToIntBits(float)}, of the primitive
 627      * {@code float} value represented by this {@code Float}
 628      * object.
 629      *
 630      * @return a hash code value for this object.
 631      */
 632     public int hashCode() {
 633         return floatToIntBits(value);
 634     }
 635 
 636     /**
 637 


   1 /*
   2  * Copyright (c) 1994, 2011, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 539      *          {@code false} otherwise.
 540      */
 541     public boolean isInfinite() {
 542         return isInfinite(value);
 543     }
 544 
 545     /**
 546      * Returns a string representation of this {@code Float} object.
 547      * The primitive {@code float} value represented by this object
 548      * is converted to a {@code String} exactly as if by the method
 549      * {@code toString} of one argument.
 550      *
 551      * @return  a {@code String} representation of this object.
 552      * @see java.lang.Float#toString(float)
 553      */
 554     public String toString() {
 555         return Float.toString(value);
 556     }
 557 
 558     /**
 559      * Returns the value of this {@code Float} as a {@code byte} after
 560      * a narrowing primitive conversion.
 561      *
 562      * @return  the {@code float} value represented by this object
 563      *          converted to type {@code byte}
 564      * @jls 5.1.3 Narrowing Primitive Conversions
 565      */
 566     public byte byteValue() {
 567         return (byte)value;
 568     }
 569 
 570     /**
 571      * Returns the value of this {@code Float} as a {@code short}
 572      * after a narrowing primitive conversion.
 573      *
 574      * @return  the {@code float} value represented by this object
 575      *          converted to type {@code short}
 576      * @jls 5.1.3 Narrowing Primitive Conversions
 577      * @since JDK1.1
 578      */
 579     public short shortValue() {
 580         return (short)value;
 581     }
 582 
 583     /**
 584      * Returns the value of this {@code Float} as an {@code int} after
 585      * a narrowing primitive conversion.
 586      *
 587      * @return  the {@code float} value represented by this object
 588      *          converted to type {@code int}
 589      * @jls 5.1.3 Narrowing Primitive Conversions
 590      */
 591     public int intValue() {
 592         return (int)value;
 593     }
 594 
 595     /**
 596      * Returns value of this {@code Float} as a {@code long} after a
 597      * narrowing primitive conversion.
 598      *
 599      * @return  the {@code float} value represented by this object
 600      *          converted to type {@code long}
 601      * @jls 5.1.3 Narrowing Primitive Conversions
 602      */
 603     public long longValue() {
 604         return (long)value;
 605     }
 606 
 607     /**
 608      * Returns the {@code float} value of this {@code Float} object.
 609      *
 610      * @return the {@code float} value represented by this object
 611      */
 612     public float floatValue() {
 613         return value;
 614     }
 615 
 616     /**
 617      * Returns the value of this {@code Float} as a {@code double}
 618      * after a widening primitive conversion.
 619      *
 620      * @return the {@code float} value represented by this
 621      *         object converted to type {@code double}
 622      * @jls 5.1.2 Widening Primitive Conversions
 623      */
 624     public double doubleValue() {
 625         return (double)value;
 626     }
 627 
 628     /**
 629      * Returns a hash code for this {@code Float} object. The
 630      * result is the integer bit representation, exactly as produced
 631      * by the method {@link #floatToIntBits(float)}, of the primitive
 632      * {@code float} value represented by this {@code Float}
 633      * object.
 634      *
 635      * @return a hash code value for this object.
 636      */
 637     public int hashCode() {
 638         return floatToIntBits(value);
 639     }
 640 
 641     /**
 642