Class CBORFloat

java.lang.Object
org.webpki.cbor.CBORObject
org.webpki.cbor.CBORFloat
All Implemented Interfaces:
Cloneable

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 "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.

      Also see CBORObject.getDouble() and CBORObject.getFloat()

      Parameters:
      value - Java double
  • Method Details

    • formatDouble

      public static String formatDouble(Double value)
      Returns number in diagnostic notation.

      Floating point numbers are always 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.
      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 to CBORFloat in order to access size().

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