public final class RyuDouble extends Object
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()
).
Modifier and Type | Field and 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.
|
Modifier and Type | Method and 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.
|
public static final int DEFAULT_LOW_EXP
public static final int DEFAULT_HIGH_EXP
public static String doubleToString(double value)
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 call doubleToString(value, -3, 7)
.
value
- double number to convertdoubleToString(double, int, int)
,
DEFAULT_LOW_EXP
,
DEFAULT_HIGH_EXP
public static String doubleToString(double value, int lowExp, int highExp)
Number inside of the interval [10lowExp, 10highExp] are represented using decimal notation, numbers outside of this range are represented using scientific notation.
value
- double number to convertlowExp
- lowest decimal exponent for which decimal notation can be usedhighExp
- highest decimal exponent for which decimal notation can be useddoubleToString(double)
,
DEFAULT_LOW_EXP
,
DEFAULT_HIGH_EXP
Copyright © 2016-2022 CS GROUP. All rights reserved.