Package org.hipparchus.util
Class RyuDouble
- java.lang.Object
-
- org.hipparchus.util.RyuDouble
-
public final class RyuDouble extends Object
An implementation of Ryū for double.Ryū generates the shortest decimal representation of a floating point number that maintains round-trip safety. That is, a correct parser can recover the exact original number. Ryū is very fast (about 10 time faster than
Double.toString()
).- See Also:
- Ryū: fast float-to-string conversion
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_HIGH_EXP
Default high switch level to scientific notation.static int
DEFAULT_LOW_EXP
Default low switch level to scientific notation.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
doubleToString(double value)
Convert a double to shortest string representation, preserving full accuracy.static String
doubleToString(double value, int lowExp, int highExp)
Convert a double to shortest string representation, preserving full accuracy.
-
-
-
Field Detail
-
DEFAULT_LOW_EXP
public static final int DEFAULT_LOW_EXP
Default low switch level to scientific notation.- See Also:
- Constant Field Values
-
DEFAULT_HIGH_EXP
public static final int DEFAULT_HIGH_EXP
Default high switch level to scientific notation.- See Also:
- Constant Field Values
-
-
Method Detail
-
doubleToString
public static String doubleToString(double value)
Convert a double to shortest string representation, preserving full accuracy.This implementation uses the same specifications as
Double.toString()
, i.e. it uses scientific notation if for numbers smaller than 10⁻³ or larger than 10⁺⁷, and decimal notion in between. That is it calldoubleToString(value, -3, 7)
.- Parameters:
value
- double number to convert- Returns:
- shortest string representation
- See Also:
doubleToString(double, int, int)
,DEFAULT_LOW_EXP
,DEFAULT_HIGH_EXP
-
doubleToString
public static String doubleToString(double value, int lowExp, int highExp)
Convert a double to shortest string representation, preserving full accuracy.Number inside of the interval [10lowExp, 10highExp] are represented using decimal notation, numbers outside of this range are represented using scientific notation.
- Parameters:
value
- double number to convertlowExp
- lowest decimal exponent for which decimal notation can be usedhighExp
- highest decimal exponent for which decimal notation can be used- Returns:
- shortest string representation
- See Also:
doubleToString(double)
,DEFAULT_LOW_EXP
,DEFAULT_HIGH_EXP
-
-