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 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 Details

    • CBORFloat

      public CBORFloat(double value)
      Creates a CBOR floating 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() and CBORObject.getFloat32()

      Parameters:
      value - Java double
  • 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 - 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 to CBORFloat in order to access size().

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