OSDN Git Service

Initial revision
[pf3gnuchains/gcc-fork.git] / libjava / java / lang / Float.java
1 /* Copyright (C) 1998, 1999  Cygnus Solutions
2
3    This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7 details.  */
8  
9 package java.lang;
10
11 /**
12  * @author Andrew Haley <aph@cygnus.com>
13  * @date September 25, 1998.  
14  */
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.
19  */
20
21 public final class Float extends Number
22 {
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;
28
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;
32
33   private float value;
34
35   public Float (float value)
36   {
37     this.value = value;
38   }
39
40   public Float (double value)
41   {
42     this.value = (float)value;
43   }
44
45   public Float (String s) throws NumberFormatException
46   {
47     this.value = valueOf (s).floatValue ();
48   }
49
50   public String toString ()
51   {
52     return toString (value);
53   }
54
55   public boolean equals (Object obj)
56   {
57     if (obj == null)
58       return false;
59
60     if (!(obj instanceof Float))
61       return false;
62
63     Float f = (Float) obj;
64
65     return floatToIntBits (value) == floatToIntBits (f.floatValue ());
66   }
67
68   public int hashCode ()
69   {
70     return floatToIntBits (value);
71   }
72
73   public int intValue ()
74   {
75     return (int) value;
76   }
77
78   public long longValue ()
79   {
80     return (long) value;
81   }
82
83   public float floatValue ()
84   {
85     return (float) value;
86   }
87
88   public double doubleValue ()
89   {
90     return (double) value;
91   }
92
93   public byte byteValue ()
94   {
95     return (byte) value;
96   }
97
98   public short shortValue ()
99   {
100     return (short) value;
101   }
102
103   public static String toString (float v)
104   {
105     return Double.toString ((double) v, true);
106   } 
107
108   public static Float valueOf (String s) throws NullPointerException, 
109     NumberFormatException
110   {
111     if (s == null)
112       throw new NullPointerException ();
113
114     return new Float (Double.valueOf (s).floatValue ());
115   }
116
117   public boolean isNaN ()
118   {
119     return isNaN (value);
120   }
121
122   public static boolean isNaN (float v)
123   {
124     int bits = floatToIntBits (v);
125     int e = bits & 0x7f800000;
126     int f = bits & 0x007fffff;
127
128     return e == 0x7f800000 && f != 0;
129   }
130
131   public boolean isInfinite ()
132   {
133     return isInfinite (value);
134   }
135
136   public static boolean isInfinite (float v)
137   {
138     int bits = floatToIntBits (v);
139     int f = bits & 0x7fffffff;
140
141     return f == 0x7f800000;
142   }
143
144   public static native int floatToIntBits (float value);
145
146   public static native float intBitsToFloat (int bits);
147
148 }
149