Package org.webpki.cbor
Class CBORFloat
java.lang.Object
org.webpki.cbor.CBORObject
org.webpki.cbor.CBORFloat
- All Implemented Interfaces:
Cloneable
,Comparable<CBORObject>
Class for holding CBOR
floating point
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
formatDouble
(Double value) Get number in diagnostic notation.int
size()
Get size of the optimized IEEE 754 type.Methods inherited from class org.webpki.cbor.CBORObject
checkForUnread, clone, compareTo, encode, equals, getArray, getBigInteger, getBoolean, getBytes, getFloat16, getFloat32, getFloat64, getInt16, getInt32, getInt64, getInt8, getMap, getString, getTag, getUint16, getUint32, getUint64, getUint8, hashCode, isNull, scan, toDiagnosticNotation, toString
-
Constructor Details
-
CBORFloat
public CBORFloat(double value) Creates a CBORfloating point
.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()
- Parameters:
value
- Java double
-
-
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
- The double- Returns:
- The double in string format
-
size
public int size()Get size of the optimized IEEE 754 type.Note that you must cast a
CBORObject
toCBORFloat
in order to accesssize()
.- Returns:
- Size in bytes: 2, 4, or 8.
-