Package org.webpki.cbor
Class CBORFloat
java.lang.Object
org.webpki.cbor.CBORObject
org.webpki.cbor.CBORFloat
- All Implemented Interfaces:
Cloneable
Class for holding CBOR
floating point
objects.
Numbers are constrained to the IEEE 754 notation using the length 16, 32, and 64 bit on "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) Returns number in diagnostic notation.int
size()
Returns the size of the optimized IEEE 754 type.Methods inherited from class org.webpki.cbor.CBORObject
checkForUnread, clone, decode, decode, encode, equals, getArray, getBigInteger, getBoolean, getByte, getBytes, getDouble, getFloat, getInt, getLong, getMap, getShort, getString, getTag, getType, getUnsignedByte, getUnsignedInt, getUnsignedLong, getUnsignedShort, 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.Also see
CBORObject.getDouble()
andCBORObject.getFloat()
- Parameters:
value
- Java double
-
-
Method Details
-
formatDouble
Returns number in diagnostic notation.Floating point numbers are always serialized using at least one integer digit (may be
Possible exponents are written as0
), a decimal point, and one or more fractional digits.e±
n, where n !=0
.- Parameters:
value
- The double- Returns:
- The double in string format
-
size
public int size()Returns the 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.
-