1 9 package org.jscience.mathematics.numbers; 10 11 import org.jscience.mathematics.structures.Field; 12 13 import javolution.lang.MathLib; 14 import javolution.text.Text; 15 import javolution.text.TypeFormat; 16 import javolution.xml.XMLFormat; 17 import javolution.xml.stream.XMLStreamException; 18 19 25 public final class Float64 extends Number <Float64> implements Field<Float64> { 26 27 32 protected static final XMLFormat<Float64> XML = new XMLFormat<Float64>(Float64.class) { 33 34 @Override 35 public Float64 newInstance(Class <Float64> cls, InputElement xml) 36 throws XMLStreamException { 37 return Float64.valueOf(xml.getAttribute("value", 0.0)); 38 } 39 40 public void write(Float64 float64, OutputElement xml) 41 throws XMLStreamException { 42 xml.setAttribute("value", float64._value); 43 } 44 45 public void read(InputElement xml, Float64 float64) { 46 } 48 }; 49 50 53 private static final Factory<Float64> FACTORY = new Factory<Float64>() { 54 55 public Float64 create() { 56 return new Float64(); 57 } 58 }; 59 60 63 public static final Float64 ZERO = new Float64(0.0); 64 65 68 public static final Float64 ONE = new Float64(1.0); 69 70 73 private double _value; 74 75 78 private Float64() { 79 } 80 81 86 private Float64(double doubleValue) { 87 _value = doubleValue; 88 } 89 90 97 public static Float64 valueOf(double doubleValue) { 98 Float64 r = FACTORY.object(); 99 r._value = doubleValue; 100 return r; 101 } 102 103 109 public static Float64 valueOf(CharSequence chars) { 110 Float64 r = FACTORY.object(); 111 r._value = TypeFormat.parseDouble(chars); 112 return r; 113 } 114 115 121 public boolean isInfinite() { 122 return Double.isInfinite(_value); 123 } 124 125 131 public boolean isNaN() { 132 return Double.isNaN(_value); 133 } 134 135 140 public Float64 opposite() { 141 Float64 r = FACTORY.object(); 142 r._value = -this._value; 143 return r; 144 } 145 146 152 public Float64 plus(Float64 that) { 153 Float64 r = FACTORY.object(); 154 r._value = this._value + that._value; 155 return r; 156 } 157 158 164 public Float64 minus(Float64 that) { 165 Float64 r = FACTORY.object(); 166 r._value = this._value - that._value; 167 return r; 168 } 169 170 176 public Float64 times(Float64 that) { 177 Float64 r = FACTORY.object(); 178 r._value = this._value * that._value; 179 return r; 180 } 181 182 187 public Float64 inverse() { 188 Float64 r = FACTORY.object(); 189 r._value = 1.0 / this._value; 190 return r; 191 } 192 193 199 public Float64 divide(Float64 that) { 200 Float64 r = FACTORY.object(); 201 r._value = this._value / that._value; 202 return r; 203 } 204 205 210 public boolean isLargerThan(Float64 that) { 211 return MathLib.abs(this._value) > MathLib.abs(that._value); 212 } 213 214 219 public Float64 abs() { 220 Float64 r = FACTORY.object(); 221 r._value = MathLib.abs(this._value); 222 return r; 223 } 224 225 230 public Float64 sqrt() { 231 Float64 r = FACTORY.object(); 232 r._value = MathLib.sqrt(this._value); 233 return r; 234 } 235 236 242 public Float64 exp() { 243 Float64 r = FACTORY.object(); 244 r._value = MathLib.exp(this._value); 245 return r; 246 } 247 248 253 public Float64 log() { 254 Float64 r = FACTORY.object(); 255 r._value = MathLib.log(this._value); 256 return r; 257 } 258 259 265 public Float64 pow(double e) { 266 Float64 r = FACTORY.object(); 267 r._value = MathLib.pow(this._value, e); 268 return r; 269 } 270 271 277 public Float64 pow(Float64 that) { 278 Float64 r = FACTORY.object(); 279 r._value = MathLib.pow(this._value, that._value); 280 return r; 281 } 282 283 288 public Text toText() { 289 return Text.valueOf(_value); 290 } 291 292 299 public boolean equals(Object that) { 300 return (that instanceof Float64) 301 && (this._value == ((Float64) that)._value); 302 } 303 304 309 public int hashCode() { 310 int h = Float.floatToIntBits((float) _value); 311 h += ~(h << 9); 312 h ^= (h >>> 14); 313 h += (h << 4); 314 return h ^ (h >>> 10); 315 } 316 317 @Override 318 public long longValue() { 319 return (long) _value; 320 } 321 322 @Override 323 public double doubleValue() { 324 return _value; 325 } 326 327 @Override 328 public int compareTo(Float64 that) { 329 if (this._value < that._value) { 330 return -1; 331 } else if (this._value > that._value) { 332 return 1; 333 } else { 334 long l1 = Double.doubleToLongBits(this._value); 335 long l2 = Double.doubleToLongBits(that._value); 336 return (l1 == l2 ? 0 : (l1 < l2 ? -1 : 1)); 337 } 338 } 339 340 private static final long serialVersionUID = 1L; 341 } | Popular Tags |