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 ANumericabs()Gets the absolute value of this number.abstract ANumericAdds a second numeric value to this valueabstract doubleabstract CVMLongGets the numeric value as a Long integer, or null if not a valid Longabstract booleanisZero()Check if this numeric value is equal to zeroabstract ANumericMultiplies a second numeric value with this valueabstract ANumericnegate()Negates this numeric valueabstract Class<?>Gets the numeric type that should be used as for calculationsabstract APrimitivesignum()Gets the signum of this numerical value.abstract ANumericSubtracts a second numeric value to this valueabstract CVMDoubletoDouble()Casts to a CVM Double value.abstract AIntegerConverts this numeric value to the nearest integerabstract CVMLongtoLong()Casts to a CVM Long value.Methods inherited from class convex.core.data.prim.APrimitive
calcMemorySize, getRefCount, isCanonical, isCVMValue, isEmbedded, longValue, toCanonicalMethods 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, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods 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:
doubleValuein 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
-
isZero
public abstract boolean isZero()Check if this numeric value is equal to zero- Returns:
- True if this value is numerically equal to zero
-