Package com.amazon.ion
Interface IonFloat
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 usedecimal 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:
-
Field Summary
Fields inherited from interface com.amazon.ion.IonValue
EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionGets the value of this Ionfloatas a JavaBigDecimal.clone()Creates a copy of this value and all of its children.doubleGets the value of this Ionfloatas a Javadoublevalue.floatGets the value of this Ionfloatas a Javafloatvalue.booleanDetermines whether this value is numeric.voidsetValue(double value) Sets the value of this element.voidsetValue(float value) Sets the value of this element.voidsetValue(BigDecimal value) Sets the value of this element.Methods inherited from interface com.amazon.ion.IonValue
accept, addTypeAnnotation, clearTypeAnnotations, equals, getContainer, getFieldId, getFieldName, getFieldNameSymbol, getSymbolTable, getSystem, getType, getTypeAnnotations, getTypeAnnotationSymbols, hashCode, hasTypeAnnotation, isNullValue, isReadOnly, makeReadOnly, removeFromContainer, removeTypeAnnotation, setTypeAnnotations, setTypeAnnotationSymbols, topLevelValue, toPrettyString, toString, toString, writeTo
-
Method Details
-
floatValue
Gets the value of this Ionfloatas a Javafloatvalue.- Returns:
- the float value.
- Throws:
NullValueException- ifthis.isNullValue().
-
doubleValue
Gets the value of this Ionfloatas a Javadoublevalue.- Returns:
- the double value.
- Throws:
NullValueException- ifthis.isNullValue().
-
bigDecimalValue
Gets the value of this Ionfloatas a JavaBigDecimal. This follows the behavior ofBigDecimal.valueOf(double). It's recommended to callisNumericValue()before calling this method. If you need negative zeros, usedoubleValue().- Specified by:
bigDecimalValuein interfaceIonNumber- Returns:
- the
BigDecimalvalue, ornullifthis.isNullValue(). - Throws:
NumberFormatException- if this value isnan,+inf, or-inf, becauseBigDecimalcannot 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
Sets the value of this element. Since Ionfloats are essentially Javadoubles, this performs a narrowing conversion as described byBigDecimal.doubleValue().- Parameters:
value- the new value of this float; may benullto make thisnull.float.
-
isNumericValue
boolean isNumericValue()Determines whether this value is numeric. Returns true if this value is none ofnull,nan,+inf, and-inf, and false if it is any of them.- Specified by:
isNumericValuein interfaceIonNumber- Returns:
- a checked condition whether this value is numeric.
-
clone
Description copied from interface:IonValueCreates 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 instanceIonValue.isReadOnly().The cloned value will be created in the context of the same
ValueFactoryas this instance; if you want a copy using a different factory, then useValueFactory.clone(IonValue)instead.- Specified by:
clonein interfaceIonValue- Throws:
UnknownSymbolException- if any part of this value has unknown text but known Sid for its field name, annotation or symbol.
-