Class CBORNonFinite

java.lang.Object
org.webpki.cbor.CBORObject
org.webpki.cbor.CBORNonFinite
All Implemented Interfaces:
Cloneable, Comparable<CBORObject>

public class CBORNonFinite extends CBORObject
Class for holding CBOR non-finite floating-point objects.

Due to the fact that platform support for non-finite floating-point objects beyond the three simple forms, "quiet" NaN, Infinity, and -Infinity is limited, this implementation separates non-finite floating-point objects from "regular" floating-point numbers. The latter are dealt with by the CBORFloat class.

Since non-finite data can be "anything" that makes sence for consuming applications, long is used as value container.

For a detailed description and user guide, turn to: Non-Finite Numbers.

  • Constructor Details

    • CBORNonFinite

      public CBORNonFinite(long value)
      Creates a non-finite floating-point number.

      The constructor takes a 16, 32, or 64-bit non-finite number in IEEE 754 encoding.

      See also CBORFloat(double) and CBORFloat.createExtendedFloat(double).

      Parameters:
      value - Non-finite number expressed as a long
      Throws:
      CBORException - If the argument is not within the non-finite number space
  • Method Details

    • createPayloadObject

      public static CBORNonFinite createPayloadObject(long payload)
      Creates a payload object.
      For details turn to Payload Option.
      Parameters:
      payload - Payload data
      Returns:
      CBORNonFinite
    • getPayload

      public long getPayload()
      Get payload data.

      This method is the "consumer" counterpart to createPayloadObject(long).

      Returns:
      Payload
    • setSign

      public CBORNonFinite setSign(boolean sign)
      Set sign bit of non-finite object.
      Parameters:
      sign - Sign bit expressed as a boolean. true = 1, false = 0.
      Returns:
      CBORNonFinite
      See Also:
    • getSign

      public boolean getSign()
      Get sign bit of non-finite object.

      This method returns true if the sign bit is 1, else false is returned.

      Returns:
      boolean.
      See Also:
    • length

      public int length()
      Get length of non-finite object.

      Note that you must cast a CBORObject to CBORNonFinite in order to access length().

      Returns:
      Length in bytes: 2, 4, or 8.
    • isSimple

      public boolean isSimple()
      Check if non-finite object is simple.

      This method returns true if the non-finite object is a Double.NaN, Double.POSITIVE_INFINITY, or Double.NEGATIVE_INFINITY, else false is returned.

      Returns:
      boolean.
    • isNaN

      public boolean isNaN()
      Check if non-finite object is a NaN.

      This method returns true for all conformant NaN variants, else false is returned..

      Returns:
      boolean.
    • getNonFinite

      public long getNonFinite()
      Get actual non-finite object (value).

      This method returns the value of a 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 a long
    • getNonFinite64

      public long getNonFinite64()
      Get expanded non-finite object (value).

      This method returns the value of a non-finite object after it has been expanded to 64 bits. That is, a received 7c01 will be returned as 7ff0040000000000.

      Returns:
      IEEE 754 non-finite number coded as a long