Class CBORNonFinite
- All Implemented Interfaces:
Cloneable
,Comparable<CBORObject>
float
objects.
See also CBORFloat
.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CBORNonFinite
createPayloadObject
(long payload) Creates a payload object.long
Get actual CBOR non-finitefloat
object.long
Get expanded CBOR non-finitefloat
object.long
Get payload data.boolean
getSign()
Get the sign bit of the non-finitefloat
.boolean
isNaN()
Check if CBOR non-finite object is aNaN
.boolean
isSimple()
Check if CBOR non-finite object is simple.int
length()
Get length of CBOR non-finite object.setSign
(boolean on) Set the sign bit of the non-finitefloat
.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
-
CBORNonFinite
public CBORNonFinite(long value) Creates a CBOR non-finitefloat
object.The constructor takes a
16
,32
, or64
-bit non-finite number inIEEE-754
encoding.See also
CBORFloat(double)
andCBORFloat.createExtendedFloat(double)
.- Parameters:
value
-long
holding the number- Throws:
CBORException
- If the argument is not within the non-finite number space
-
-
Method Details
-
createPayloadObject
Creates a payload object.Traditionally, the non-finite number space is used for propagating math-related problems such as division by zero.However, in some cases there may be a desire providing more application specific data, like debug information related to faulty sensors. ThecreatePayloadObject(long)
andgetPayloadData()
methods were designed for this particular purpose. To obviate the need defining another CBOR type, these methods are "piggybacking" on the existing non-finite number space. The following table represents these methods from a developer perspective:Payload d51-d0
in big-endian orderThe payload bits are conceptually put into anIEEE-754
64
-bit object having the following layout:Sign Exponent Significand 0 11111111111 d0-d51
in little-endian orderThe reason for reversing the payload bits is to ensure that a specific bit will remain in a fix position (maintain the same value), independent of the size of theIEEE-754
variant used for encoding. For setting the sign bit, seesetSign(boolean)
.Note that the encoder will (due to CBOR deterministic encoding rules), select the shortest serialization required to properly represent the payload. The following table shows a few examples:Payload (hex) CBOR Encoding Diagnostic Notation 0
f97c00
Infinity
1
f97e00
NaN
2
f97d00
float'7d00'
3ff
f97fff
float'7fff'
400
fa7f801000
float'7f801000'
7fffff
fa7fffffff
float'7fffffff'
800000
fb7ff0000010000000
float'7ff0000010000000'
fffffffffffff
fb7fffffffffffffff
float'7fffffffffffffff'
CBORNonFinite(long)
represents another way creating a non-finitefloat
.- Parameters:
payload
- Payload- Returns:
CBORNonFinite
. Also see CBOR wrapper objects.- See Also:
-
getPayloadData
public long getPayloadData()Get payload data.This method is the "consumer" counterpart to
createPayloadObject(long)
.- Returns:
- Payload
-
setSign
Set the sign bit of the non-finitefloat
.- Parameters:
on
- Sign bit- Returns:
CBORNonFinite
- See Also:
-
getSign
public boolean getSign()Get the sign bit of the non-finitefloat
.- Returns:
- Sign bit expressed as a
boolean
- See Also:
-
length
public int length()Get length of CBOR non-finite object.Note that you must cast a
CBORObject
toCBORNonFinite
in order to accesslength()
.- Returns:
- Length in bytes: 2, 4, or 8.
-
isSimple
public boolean isSimple()Check if CBOR non-finite object is simple.This method returns
true
if the non-finite object is a "quiet"NaN
,Infinity
, or-Infinity
, else it returnsfalse
.- Returns:
boolean
.
-
isNaN
public boolean isNaN()Check if CBOR non-finite object is aNaN
.This method returns
true
for all conformantNaN
variants, else it returnsfalse
.- Returns:
boolean
.
-
getNonFinite
public long getNonFinite()Get actual CBOR non-finitefloat
object.This method returns the value of a CBOR non-finite object. The value is provided in the most compact form based on CBOR serialization rules.
- Returns:
IEEE-754
non-finite number coded as along
-
getNonFinite64
public long getNonFinite64()Get expanded CBOR non-finitefloat
object.This method returns the value of a CBOR non-finite object after it has been expanded to 64 bits. That is, a received
7c01
will be returned as7ff0040000000000
.- Returns:
IEEE-754
non-finite number coded as along
-