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 CBORObject
createExtendedFloat
(double value) Creates an "extended" CBORfloat
object.static String
formatDouble
(Double value) Get number in diagnostic notation.int
length()
Get length of the serialized IEEE 754 type.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, 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.This constructor only implements support for finite ("genuine") floating point numbers. That is, a
Double.NaN
argument causes aCBORException
to be thrown.CBORObject.getFloat64()
is the decoder counterpart.For
NaN
andInfinity
support seecreateExtendedFloat(double)
.- Parameters:
value
- Floating-point value
-
-
Method Details
-
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
- Floating-point value- Returns:
- The double in string format
-
createExtendedFloat
Creates an "extended" CBORfloat
object.Unlike
CBORFloat(double)
, this method also supports the "quiet"NaN
and the twoInfinity
variants.CBORObject.getExtendedFloat64()
is the decoder counterpart.Note that return type is either
CBORFloat
orCBORNonFinite
, depending on if the argument is a "regular" floating-point value of one of the non-finite variants.- Parameters:
value
- Floating-point value- Returns:
CBORObject
- Throws:
CBORException
-
length
public int length()Get length of the serialized IEEE 754 type.Note that you must cast a
CBORObject
toCBORFloat
in order to accesslength()
.- Returns:
- Length in bytes: 2, 4, or 8.
-