Package org.jscience.mathematics.number
Class Number<T extends Number<T>>
- java.lang.Object
-
- java.lang.Number
-
- org.jscience.mathematics.number.Number<T>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<T>,javolution.lang.Immutable,javolution.lang.Realtime,javolution.lang.ValueType,javolution.xml.XMLSerializable,GroupAdditive<T>,Ring<T>,Structure<T>
- Direct Known Subclasses:
Complex,Float64,FloatingPoint,Integer64,LargeInteger,ModuloInteger,Rational,Real
public abstract class Number<T extends Number<T>> extends java.lang.Number implements Ring<T>, java.lang.Comparable<T>, javolution.lang.Realtime, javolution.xml.XMLSerializable
This class represents a
value-typenumber.- Version:
- 3.0, February 13, 2006
- Author:
- Jean-Marie Dautelle
- See Also:
- Wikipedia: Number, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Number()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description bytebyteValue()Returns the value of this number as abyte.abstract intcompareTo(T that)Compares this number with the specified number for order.abstract Number<T>copy()Returns a copy of this numberallocatedby the calling thread (possibly on the stack).abstract doubledoubleValue()Returns the value of this number as adouble.abstract booleanequals(java.lang.Object obj)Indicates if this number is equals to the specified object.floatfloatValue()Returns the value of this number as afloat.abstract inthashCode()Returns the hash code for this number (consistent withequals(Object).intintValue()Returns the value of this number as anint.booleanisGreaterThan(T that)Indicates if this number is ordered after that number (convenience method).abstract booleanisLargerThan(T that)Compares the magnitude of this number with that number.booleanisLessThan(T that)Indicates if this number is ordered before that number (convenience method).abstract longlongValue()Returns the value of this number as along.Tminus(T that)Returns the difference between this number and the one specified.Tpow(int exp)Returns this number raised at the specified positive exponent.shortshortValue()Returns the value of this number as ashort.java.lang.StringtoString()Returns the text representation of this number as ajava.lang.String.abstract javolution.text.TexttoText()Returns the textual representation of this real-time object (equivalent totoStringexcept that the returned value can be allocated from the local context space).-
Methods inherited from interface org.jscience.mathematics.structure.GroupAdditive
opposite, plus
-
-
-
-
Constructor Detail
-
Number
public Number()
-
-
Method Detail
-
isLargerThan
public abstract boolean isLargerThan(T that)
Compares the magnitude of this number with that number.- Returns:
|this| > |that|
-
longValue
public abstract long longValue()
Returns the value of this number as along.- Specified by:
longValuein classjava.lang.Number- Returns:
- the numeric value represented by this object after conversion
to type
long.
-
doubleValue
public abstract double doubleValue()
Returns the value of this number as adouble.- Specified by:
doubleValuein classjava.lang.Number- Returns:
- the numeric value represented by this object after conversion
to type
double.
-
compareTo
public abstract int compareTo(T that)
Compares this number with the specified number for order. Returns a negative integer, zero, or a positive integer as this number is less than, equal to, or greater than the specified number. Implementation must ensure that this method is consistent with equals(x.compareTo(y)==0) == (x.equals(y)),
-
isLessThan
public final boolean isLessThan(T that)
Indicates if this number is ordered before that number (convenience method).- Parameters:
that- the number to compare with.- Returns:
this.compareTo(that) < 0.
-
isGreaterThan
public final boolean isGreaterThan(T that)
Indicates if this number is ordered after that number (convenience method).- Parameters:
that- the number to compare with.- Returns:
this.compareTo(that) > 0.
-
minus
public T minus(T that)
Returns the difference between this number and the one specified.- Parameters:
that- the number to be subtracted.- Returns:
this - that.
-
pow
public T pow(int exp)
Returns this number raised at the specified positive exponent.- Parameters:
exp- the positive exponent.- Returns:
thisexp- Throws:
java.lang.IllegalArgumentException- ifexp <= 0
-
byteValue
public final byte byteValue()
Returns the value of this number as abyte. This may involve rounding or truncation.- Overrides:
byteValuein classjava.lang.Number- Returns:
- the numeric value represented by this object after conversion
to type
byte.
-
shortValue
public final short shortValue()
Returns the value of this number as ashort. This may involve rounding or truncation.- Overrides:
shortValuein classjava.lang.Number- Returns:
- the numeric value represented by this object after conversion
to type
short.
-
intValue
public final int intValue()
Returns the value of this number as anint. This may involve rounding or truncation.- Specified by:
intValuein classjava.lang.Number- Returns:
- the numeric value represented by this object after conversion
to type
int.
-
floatValue
public final float floatValue()
Returns the value of this number as afloat. This may involve rounding.- Specified by:
floatValuein classjava.lang.Number- Returns:
- the numeric value represented by this object after conversion
to type
float.
-
equals
public abstract boolean equals(java.lang.Object obj)
Indicates if this number is equals to the specified object.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to be compared with.- Returns:
trueif this number and the specified argument represent the same number;falseotherwise.
-
hashCode
public abstract int hashCode()
Returns the hash code for this number (consistent withequals(Object).- Overrides:
hashCodein classjava.lang.Object- Returns:
- this number hash code.
-
toText
public abstract javolution.text.Text toText()
Returns the textual representation of this real-time object (equivalent totoStringexcept that the returned value can be allocated from the local context space).- Specified by:
toTextin interfacejavolution.lang.Realtime- Returns:
- this object's textual representation.
-
copy
public abstract Number<T> copy()
Returns a copy of this numberallocatedby the calling thread (possibly on the stack).- Specified by:
copyin interfacejavolution.lang.ValueType- Returns:
- an identical and independant copy of this number.
-
toString
public final java.lang.String toString()
Returns the text representation of this number as ajava.lang.String.- Overrides:
toStringin classjava.lang.Object- Returns:
toText().toString()
-
-