Class CBORFloat
- All Implemented Interfaces:
Cloneable,Comparable<CBORObject>
float objects.
Floating-point numbers are expressed in the
IEEE 754 format
using the length 16, 32, and 64 bit on the "wire".
Which length to use is governed by the size and precision
required to (minimally) correctly represent a value.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CBORObjectcreateExtendedFloat(double value) Creates an "extended" CBORfloatobject.static CBORFloatcreateFloat16(double value) Creates a CBORfloat16object.static CBORFloatcreateFloat32(double value) Creates a CBORfloat32object.intlength()Get length of the serializedIEEE754object.Methods inherited from class org.webpki.cbor.CBORObject
checkForUnread, clone, compareTo, encode, equals, getArray, getBigInteger, getBoolean, getBytes, getDateTime, getEpochTime, getExtendedFloat64, getFloat16, getFloat32, getFloat64, getInt16, getInt32, getInt53, getInt64, getInt8, getMap, getSimple, getString, getTag, getUint16, getUint32, getUint64, getUint8, hashCode, isNull, scan, toDiagnostic, toString
-
Constructor Details
-
CBORFloat
public CBORFloat(double value) Creates a CBORfloatobject.This constructor only implements support for finite ("regular") floating point numbers. That is, a
Double.NaNargument causes aCBORExceptionto be thrown.CBORObject.getFloat64()is the decoder counterpart.For
NaNandInfinitysupport seecreateExtendedFloat(double).- Parameters:
value- Floating-point value
-
-
Method Details
-
createExtendedFloat
Creates an "extended" CBORfloatobject.Unlike
CBORFloat(double), this method also supports theDouble.NaN,Double.POSITIVE_INFINITY, andDouble.NEGATIVE_INFINITYnon-finite variants.CBORObject.getExtendedFloat64()is the decoder counterpart.Note that return type is either
CBORFloatorCBORNonFinite, depending on if the argument is a "regular" floating-point value or one of the non-finite variants.- Parameters:
value- Floating-point value- Returns:
CBORObject- Throws:
CBORException- See Also:
-
createFloat32
Creates a CBORfloat32object.This method creates a
CBORFloatobject, where the value is converted to fit CBORfloat32representation.If the value (after applying
IEEE754conversion rules), is out of range, aCBORExceptionis thrown.Note that this method returns a
float16compatible object if the value and precision is equivalent to thefloat32representation (e.g.2.5).- Parameters:
value- Floating-point value- Returns:
CBORFloat- Throws:
CBORException- See Also:
-
createFloat16
Creates a CBORfloat16object.This method creates a
CBORFloatobject, where the value is converted to fit CBORfloat16representation.If the value (after applying
IEEE754conversion rules), is out of range, aCBORExceptionis thrown.- Parameters:
value- Floating-point value- Returns:
CBORFloat- Throws:
CBORException- See Also:
-
length
public int length()Get length of the serializedIEEE754object.Note that you must cast a
CBORObjecttoCBORFloatin order to accesslength().- Returns:
- Length in bytes: 2, 4, or 8.
-