1 /* Copyright (C) 1998, 1999 Cygnus Solutions
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 * @author Andrew Haley <aph@cygnus.com>
13 * @date September 25, 1998.
15 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
16 * "The Java Language Specification", ISBN 0-201-63451-1
17 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
18 * Status: Believed complete and correct.
21 public final class Float extends Number
23 public static final float MAX_VALUE = 3.4028235e+38f;
24 public static final float MIN_VALUE = 1.4e-45f;
25 public static final float NEGATIVE_INFINITY = -1.0f/0.0f;
26 public static final float POSITIVE_INFINITY = 1.0f/0.0f;
27 public static final float NaN = 0.0f/0.0f;
29 // This initialization is seemingly circular, but it is accepted
30 // by javac, and is handled specially by gcc.
31 public static final Class TYPE = float.class;
35 public Float (float value)
40 public Float (double value)
42 this.value = (float)value;
45 public Float (String s) throws NumberFormatException
47 this.value = valueOf (s).floatValue ();
50 public String toString ()
52 return toString (value);
55 public boolean equals (Object obj)
60 if (!(obj instanceof Float))
63 Float f = (Float) obj;
65 return floatToIntBits (value) == floatToIntBits (f.floatValue ());
68 public int hashCode ()
70 return floatToIntBits (value);
73 public int intValue ()
78 public long longValue ()
83 public float floatValue ()
88 public double doubleValue ()
90 return (double) value;
93 public byte byteValue ()
98 public short shortValue ()
100 return (short) value;
103 public static String toString (float v)
105 return Double.toString ((double) v, true);
108 public static Float valueOf (String s) throws NullPointerException,
109 NumberFormatException
112 throw new NullPointerException ();
114 return new Float (Double.valueOf (s).floatValue ());
117 public boolean isNaN ()
119 return isNaN (value);
122 public static boolean isNaN (float v)
124 int bits = floatToIntBits (v);
125 int e = bits & 0x7f800000;
126 int f = bits & 0x007fffff;
128 return e == 0x7f800000 && f != 0;
131 public boolean isInfinite ()
133 return isInfinite (value);
136 public static boolean isInfinite (float v)
138 int bits = floatToIntBits (v);
139 int f = bits & 0x7fffffff;
141 return f == 0x7f800000;
144 public static native int floatToIntBits (float value);
146 public static native float intBitsToFloat (int bits);