Interface IonFloat

All Superinterfaces:
Cloneable, IonNumber, IonValue

public interface IonFloat extends IonNumber
An Ion float value.

WARNING: This interface should not be implemented or extended by code outside of this library.

Precision Problems

Use of binary floating-point numbers is prone to countless problems. The vast majority of applications should use decimal values instead. Please read the Decimal Arithmetic FAQ for horror stories.

If you have any doubt whatsoever on whether you should use float or decimal, then you should use decimal.

See Also:
  • Method Details

    • floatValue

      float floatValue() throws NullValueException
      Gets the value of this Ion float as a Java float value.
      Returns:
      the float value.
      Throws:
      NullValueException - if this.isNullValue().
    • doubleValue

      double doubleValue() throws NullValueException
      Gets the value of this Ion float as a Java double value.
      Returns:
      the double value.
      Throws:
      NullValueException - if this.isNullValue().
    • bigDecimalValue

      BigDecimal bigDecimalValue() throws NullValueException
      Gets the value of this Ion float as a Java BigDecimal. This follows the behavior of BigDecimal.valueOf(double). It's recommended to call isNumericValue() before calling this method. If you need negative zeros, use doubleValue().
      Specified by:
      bigDecimalValue in interface IonNumber
      Returns:
      the BigDecimal value, or null if this.isNullValue().
      Throws:
      NumberFormatException - if this value is nan, +inf, or -inf, because BigDecimal cannot represent those values.
      NullValueException
    • setValue

      void setValue(float value)
      Sets the value of this element.
    • setValue

      void setValue(double value)
      Sets the value of this element.
    • setValue

      void setValue(BigDecimal value)
      Sets the value of this element. Since Ion floats are essentially Java doubles, this performs a narrowing conversion as described by BigDecimal.doubleValue().
      Parameters:
      value - the new value of this float; may be null to make this null.float.
    • isNumericValue

      boolean isNumericValue()
      Determines whether this value is numeric. Returns true if this value is none of null, nan, +inf, and -inf, and false if it is any of them.
      Specified by:
      isNumericValue in interface IonNumber
      Returns:
      a checked condition whether this value is numeric.
    • clone

      Description copied from interface: IonValue
      Creates a copy of this value and all of its children. The cloned value may use the same shared symbol tables, but it will have an independent local symbol table if necessary. The cloned value will be modifiable regardless of whether this instance IonValue.isReadOnly().

      The cloned value will be created in the context of the same ValueFactory as this instance; if you want a copy using a different factory, then use ValueFactory.clone(IonValue) instead.

      Specified by:
      clone in interface IonValue
      Throws:
      UnknownSymbolException - if any part of this value has unknown text but known Sid for its field name, annotation or symbol.