Class CBORFloat
- All Implemented Interfaces:
Cloneable
,Comparable<CBORObject>
float
objects.
Numbers are constrained to the IEEE 754 notation 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 number.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatDouble
(Double value) Get number in diagnostic notation.int
length()
Get length of the optimized IEEE 754 type.static void
setNonFiniteFloatsMode
(boolean reject) Globally disableNaN
andInfinity
.Methods inherited from class org.webpki.cbor.CBORObject
checkForUnread, clone, compareTo, encode, equals, getArray, getBigInteger, getBoolean, getBytes, getDateTime, getEpochTime, getFloat16, getFloat32, getFloat64, getInt16, getInt32, getInt64, getInt8, getMap, getSimple, getString, getTag, getUint16, getUint32, getUint64, getUint8, hashCode, isNull, scan, toDiagnosticNotation, toString
-
Constructor Details
-
CBORFloat
public CBORFloat(double value) Creates a CBORfloat
object.Note that this implementation does not provide a specific constructor for Java
float
values. Due to the CBOR normalization algorithm, numbers are still correctly encoded.See also
CBORObject.getFloat64()
andCBORObject.getFloat32()
For
NaN
andInfinity
support seeCBORDecoder.REJECT_NON_FINITE_FLOATS
andsetNonFiniteFloatsMode(boolean)
.- Parameters:
value
- Java double- Throws:
CBORException
-
-
Method Details
-
setNonFiniteFloatsMode
public static void setNonFiniteFloatsMode(boolean reject) Globally disableNaN
andInfinity
.Note that this method unlike
CBORDecoder.REJECT_NON_FINITE_FLOATS
, also affects encoding ofNaN
andInfinity
values. Since this is a global setting. you need to consider how it could affect other applications running in the same JVM.- Parameters:
reject
- Iftrue
, disableNaN
andInfinity
support.
-
formatDouble
Get number in diagnostic notation.Floating point numbers are serialized using at least one integer digit (may be
0
), a decimal point, and one or more fractional digits.Possible exponents are written as
This method also supportse±
n, where n !=0
.NaN
,Infinity
, and-Infinity
.- Parameters:
value
- The double- Returns:
- The double in string format
-
length
public int length()Get length of the optimized IEEE 754 type.Note that you must cast a
CBORObject
toCBORFloat
in order to accesslength()
.- Returns:
- Length in bytes: 2, 4, or 8.
-