Class CBORFloat

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

public class CBORFloat extends CBORObject
Class for holding CBOR 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 Details

    • CBORFloat

      public CBORFloat(double value)
      Creates a CBOR float object.

      This constructor only implements support for finite ("genuine") floating point numbers. That is, a Double.NaN argument causes a CBORException to be thrown.

      CBORObject.getFloat64() is the decoder counterpart.

      For NaN and Infinity support see createExtendedFloat(double).

      Parameters:
      value - Floating-point value
  • Method Details

    • formatDouble

      public static String formatDouble(Double value)
      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 n, where n != 0.

      This method also supports NaN, Infinity, and -Infinity.
      Parameters:
      value - Floating-point value
      Returns:
      The double in string format
    • createExtendedFloat

      public static CBORObject createExtendedFloat(double value)
      Creates an "extended" CBOR float object.

      Unlike CBORFloat(double), this method also supports the "quiet" NaN and the two Infinity variants.

      CBORObject.getExtendedFloat64() is the decoder counterpart.

      Note that return type is either CBORFloat or CBORNonFinite, 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 to CBORFloat in order to access length().

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