Package convex.core.data.prim
Class CVMDouble
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.prim.APrimitive
convex.core.data.prim.ANumeric
convex.core.data.prim.CVMDouble
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<ANumeric>
Class for CVM double floating-point values.
Follows the Java standard / IEEE 784 spec.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final CVMDouble
static final CVMDouble
static final CVMDouble
static final CVMDouble
static final CVMDouble
static final CVMDouble
static final CVMDouble
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs()
Gets the absolute value of this number.Adds a second numeric value to this valueint
static CVMDouble
create
(double value) Creates a CVMDouble.double
int
encode
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.int
encodeRaw
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, excluding the tag byte.Gets the numeric value as a Long integer, or null if not a valid Longboolean
Checks for equality with another Cell.int
Estimate the encoded data size for this Cell.byte
getTag()
Gets the tag byte for this cell.getType()
Gets the most specific known runtime Type for this Cell.boolean
isZero()
Check if this numeric value is equal to zerolong
Multiplies a second numeric value with this valuenegate()
Negates this numeric valueClass<?>
Gets the numeric type that should be used as for calculationsstatic CVMDouble
Parses a CVM Double value.boolean
print
(BlobBuilder bb, long limit) Prints this Object to a readable String Representation.static CVMDouble
static CVMDouble
read
(double value) signum()
Gets the signum of this numerical value.Subtracts a second numeric value to this valuetoCVMString
(long limit) Returns the CVM String representation of this Cell.toDouble()
Casts to a CVM Double value.Converts this numeric value to the nearest integertoLong()
Casts to a CVM Long value.toString()
Returns the Java String representation of this Cell.void
Validates the local structure and invariants of this cell.Methods inherited from class convex.core.data.prim.APrimitive
calcMemorySize, getRefCount, isCanonical, isCVMValue, isEmbedded, toCanonical
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, hashCode, isCompletelyEncoded, mark, mark, updateRefs, validate
Methods inherited from class convex.core.data.AObject
attachEncoding, print, print
-
Field Details
-
ZERO
-
NEGATIVE_ZERO
-
ONE
-
MINUS_ONE
-
NaN
-
POSITIVE_INFINITY
-
NEGATIVE_INFINITY
-
MAX_ENCODING_LENGTH
public static final int MAX_ENCODING_LENGTH- See Also:
-
-
Constructor Details
-
CVMDouble
public CVMDouble(double value)
-
-
Method Details
-
create
Creates a CVMDouble. Forces NaN to be canonical instance.- Parameters:
value
- Double value to wrap- Returns:
- CVMDouble value
-
getType
Description copied from class:ACell
Gets the most specific known runtime Type for this Cell. -
longValue
public long longValue()- Specified by:
longValue
in classAPrimitive
- Returns:
- Java long value representing this primitive CVM value
-
toLong
Description copied from class:ANumeric
Casts to a CVM Long value. Takes last 64 bits. -
toDouble
Description copied from class:ANumeric
Casts to a CVM Double value. -
signum
Description copied from class:ANumeric
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. -
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteable
Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Returns:
- The estimated size for the binary representation of this object.
-
validateCell
Description copied from class:ACell
Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Specified by:
validateCell
in classACell
- Throws:
InvalidDataException
- If the Cell is invalid
-
encode
public int encode(byte[] bs, int pos) Description copied from class:ACell
Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encode
in interfaceIWriteable
- Specified by:
encode
in classACell
- Parameters:
bs
- A byte array to which to write the encodingpos
- The offset into the byte array- Returns:
- New position after writing
-
encodeRaw
public int encodeRaw(byte[] bs, int pos) Description copied from class:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte. -
toString
Description copied from class:ACell
Returns the Java String representation of this Cell. The String representation is intended to be a easy-to-read textual representation of the Cell's data content. -
print
Description copied from class:AObject
Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time when limit of printing is exceeded otherwise DoS attacks may be possible. -
numericType
Description copied from class:ANumeric
Gets the numeric type that should be used as for calculations- Specified by:
numericType
in classANumeric
- Returns:
- Double.class or Long.class, or null if not a numeric type
-
doubleValue
public double doubleValue()- Specified by:
doubleValue
in classANumeric
- Returns:
- Java double value representing this primitive CVM value
-
parse
Parses a CVM Double value.- Parameters:
s
- String to parse- Returns:
- CVMDouble value
- Throws:
NumberFormatException
- If number format is invalid
-
getTag
public byte getTag()Description copied from class:ACell
Gets the tag byte for this cell. The tag byte is always equal to the first byte of the Cell's canonical Encoding, and is sufficient to distinguish how to read the rest of the encoding. -
read
- Throws:
BadFormatException
-
read
- Throws:
BadFormatException
-
toCVMString
Description copied from class:ACell
Returns the CVM String representation of this Cell. Normally, this is as printed, but may be different for some types. MUST return null in O(1) time if the length of the CVM String would exceed limit. The String representation is intended to be a easy-to-read textual representation of the Cell's data content.- Overrides:
toCVMString
in classACell
- Parameters:
limit
- Limit of CVM String length in UTF-8 bytes- Returns:
- CVM String, or null if limit exceeded
-
equals
Description copied from class:ACell
Checks for equality with another Cell. In general, Cells are considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses SHOULD override this if they have a more efficient equals implementation. MUST NOT require reads from Store. -
abs
Description copied from class:ANumeric
Gets the absolute value of this number. May be ##NaN for Doubles. -
compareTo
-
ensureLong
Description copied from class:ANumeric
Gets the numeric value as a Long integer, or null if not a valid Long- Specified by:
ensureLong
in classANumeric
- Returns:
- CVMLong value, or null
-
add
Description copied from class:ANumeric
Adds a second numeric value to this value -
sub
Description copied from class:ANumeric
Subtracts a second numeric value to this value -
negate
Description copied from class:ANumeric
Negates this numeric value -
multiply
Description copied from class:ANumeric
Multiplies a second numeric value with this value -
toInteger
Description copied from class:ANumeric
Converts this numeric value to the nearest integer -
isZero
public boolean isZero()Description copied from class:ANumeric
Check if this numeric value is equal to zero
-