Package convex.core.data.prim
Class ANumeric
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.prim.APrimitive
convex.core.data.prim.ANumeric
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ANumeric>
BAse class for CVM numeric types
-
Field Summary
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ANumeric
abs()
Gets the absolute value of this number.abstract ANumeric
Adds a second numeric value to this valueabstract double
abstract CVMLong
Gets the numeric value as a Long integer, or null if not a valid Longabstract boolean
isZero()
Check if this numeric value is equal to zeroabstract ANumeric
Multiplies a second numeric value with this valueabstract ANumeric
negate()
Negates this numeric valueabstract Class<?>
Gets the numeric type that should be used as for calculationsabstract APrimitive
signum()
Gets the signum of this numerical value.abstract ANumeric
Subtracts a second numeric value to this valueabstract CVMDouble
toDouble()
Casts to a CVM Double value.abstract AInteger
Converts this numeric value to the nearest integerabstract CVMLong
toLong()
Casts to a CVM Long value.Methods inherited from class convex.core.data.prim.APrimitive
calcMemorySize, getRefCount, isCanonical, isCVMValue, isEmbedded, longValue, toCanonical
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encode, encodeRaw, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getTag, getType, hashCode, isCompletelyEncoded, mark, mark, toCVMString, toString, updateRefs, validate, validateCell
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface convex.core.data.IWriteable
estimatedEncodingSize
-
Constructor Details
-
ANumeric
public ANumeric()
-
-
Method Details
-
toLong
Casts to a CVM Long value. Takes last 64 bits.- Returns:
- Long representation of this number
-
toDouble
Casts to a CVM Double value.- Returns:
- Double value
-
doubleValue
public abstract double doubleValue()- Specified by:
doubleValue
in classAPrimitive
- Returns:
- Java double value representing this primitive CVM value
-
numericType
Gets the numeric type that should be used as for calculations- Returns:
- Double.class or Long.class, or null if not a numeric type
-
signum
Gets the signum of this numerical value. Will be -1, 0 or 1 for Longs, -1.0, 0.0 , 1.0 or ##NaN for Doubles.- Returns:
- Signum of the numeric value
-
abs
Gets the absolute value of this number. May be ##NaN for Doubles.- Returns:
- Absolute value of the numeric value
-
ensureLong
Gets the numeric value as a Long integer, or null if not a valid Long- Returns:
- CVMLong value, or null
-
add
Adds a second numeric value to this value- Parameters:
b
- Second number to add- Returns:
- Result of addition
-
sub
Subtracts a second numeric value to this value- Parameters:
b
- Number to subtract- Returns:
- Result of subtraction
-
negate
Negates this numeric value- Returns:
- Negated value
-
multiply
Multiplies a second numeric value with this value- Parameters:
b
- Second number to add- Returns:
- Result of multiplication
-
toInteger
Converts this numeric value to the nearest integer- Returns:
- Integer value, or null if bad conversion (e.g. infinity or NaN)
-
isZero
public abstract boolean isZero()Check if this numeric value is equal to zero- Returns:
- True if this value is numerically equal to zero
-