1 16 package java.lang; 17 18 21 public final class Float extends Number implements Comparable { 22 public static final float MAX_VALUE = 3.4028235e+38f; 23 public static final float MIN_VALUE = 1.4e-45f; 24 public static final float NaN = 0f / 0f; 25 public static final float NEGATIVE_INFINITY = -1f / 0f; 26 public static final float POSITIVE_INFINITY = 1f / 0f; 27 28 public static int compare(float x, float y) { 29 if (x < y) { 30 return -1; 31 } else if (x > y) { 32 return 1; 33 } else { 34 return 0; 35 } 36 } 37 38 public static native boolean isInfinite(float x) ; 41 42 public static native boolean isNaN(float x) ; 45 46 public static float parseFloat(String s) throws NumberFormatException { 47 return (float)__parseAndValidateDouble(s); 48 } 49 50 public static String toString(float b) { 51 return String.valueOf(b); 52 } 53 54 public static Float valueOf(String s) throws NumberFormatException { 55 return new Float (Float.parseFloat(s)); 56 } 57 58 private final transient float value; 59 60 public Float(float value) { 61 this.value = value; 62 } 63 64 public Float(String s) { 65 value = parseFloat(s); 66 } 67 68 public byte byteValue() { 69 return (byte) value; 70 } 71 72 public int compareTo(Float b) { 73 if (value < b.value) { 74 return -1; 75 } else if (value > b.value) { 76 return 1; 77 } else { 78 return 0; 79 } 80 } 81 82 public int compareTo(Object o) { 83 return compareTo((Float ) o); 84 } 85 86 public double doubleValue() { 87 return value; 88 } 89 90 public boolean equals(Object o) { 91 return (o instanceof Float ) && (((Float ) o).value == value); 92 } 93 94 public float floatValue() { 95 return value; 96 } 97 98 107 public int hashCode() { 108 return (int) value; 109 } 110 111 public int intValue() { 112 return (int) value; 113 } 114 115 public boolean isInfinite() { 116 return isInfinite(value); 117 } 118 119 public boolean isNaN() { 120 return isNaN(value); 121 } 122 123 public long longValue() { 124 return (long) value; 125 } 126 127 public short shortValue() { 128 return (short) value; 129 } 130 131 public String toString() { 132 return toString(value); 133 } 134 135 } 136 | Popular Tags |