Class DoubleToDecimal
- java.lang.Object
-
- com.fasterxml.jackson.core.io.schubfach.DoubleToDecimal
-
public final class DoubleToDecimal extends java.lang.ObjectThis class exposes a method to render adoubleas a string.
-
-
Field Summary
Fields Modifier and Type Field Description private static intBQ_MASKprivate byte[]bytesprivate static longC_MIN(package private) static longC_TINY(package private) static intE_MAX(package private) static intE_MIN(package private) static intHprivate intindex(package private) static intK_MAX(package private) static intK_MINprivate static intMASK_28private static longMASK_63intMAX_CHARSprivate static intMINUS_INFprivate static intMINUS_ZEROprivate static intNANprivate static intNON_SPECIAL(package private) static intPprivate static intPLUS_INFprivate static intPLUS_ZERO(package private) static intQ_MAX(package private) static intQ_MINprivate static longT_MASKprivate static intW
-
Constructor Summary
Constructors Modifier Constructor Description privateDoubleToDecimal()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidappend(int c)private voidappend8Digits(int m)private voidappendDigit(int d)private java.lang.StringcharsToString()private voidexponent(int e)private voidlowDigits(int l)private voidremoveTrailingZeroes()private static longrop(long g1, long g0, long cp)private inttoChars(long f, int e)private inttoChars1(int h, int m, int l, int e)private inttoChars2(int h, int m, int l, int e)private inttoChars3(int h, int m, int l, int e)private inttoDecimal(double v)private inttoDecimal(int q, long c, int dk)private java.lang.StringtoDecimalString(double v)static java.lang.StringtoString(double v)Returns a string rendering of thedoubleargument.private inty(int a)
-
-
-
Field Detail
-
P
static final int P
- See Also:
- Constant Field Values
-
W
private static final int W
- See Also:
- Constant Field Values
-
Q_MIN
static final int Q_MIN
- See Also:
- Constant Field Values
-
Q_MAX
static final int Q_MAX
- See Also:
- Constant Field Values
-
E_MIN
static final int E_MIN
- See Also:
- Constant Field Values
-
E_MAX
static final int E_MAX
- See Also:
- Constant Field Values
-
C_TINY
static final long C_TINY
- See Also:
- Constant Field Values
-
K_MIN
static final int K_MIN
- See Also:
- Constant Field Values
-
K_MAX
static final int K_MAX
- See Also:
- Constant Field Values
-
H
static final int H
- See Also:
- Constant Field Values
-
C_MIN
private static final long C_MIN
- See Also:
- Constant Field Values
-
BQ_MASK
private static final int BQ_MASK
- See Also:
- Constant Field Values
-
T_MASK
private static final long T_MASK
- See Also:
- Constant Field Values
-
MASK_63
private static final long MASK_63
- See Also:
- Constant Field Values
-
MASK_28
private static final int MASK_28
- See Also:
- Constant Field Values
-
NON_SPECIAL
private static final int NON_SPECIAL
- See Also:
- Constant Field Values
-
PLUS_ZERO
private static final int PLUS_ZERO
- See Also:
- Constant Field Values
-
MINUS_ZERO
private static final int MINUS_ZERO
- See Also:
- Constant Field Values
-
PLUS_INF
private static final int PLUS_INF
- See Also:
- Constant Field Values
-
MINUS_INF
private static final int MINUS_INF
- See Also:
- Constant Field Values
-
NAN
private static final int NAN
- See Also:
- Constant Field Values
-
MAX_CHARS
public final int MAX_CHARS
- See Also:
- Constant Field Values
-
bytes
private final byte[] bytes
-
index
private int index
-
-
Method Detail
-
toString
public static java.lang.String toString(double v)
Returns a string rendering of thedoubleargument.The characters of the result are all drawn from the ASCII set.
- Any NaN, whether quiet or signaling, is rendered as
"NaN", regardless of the sign bit. - The infinities +∞ and -∞ are rendered as
"Infinity"and"-Infinity", respectively. - The positive and negative zeroes are rendered as
"0.0"and"-0.0", respectively. - A finite negative
vis rendered as the sign '-' followed by the rendering of the magnitude -v. - A finite positive
vis rendered in two stages:- Selection of a decimal: A well-defined
decimal d
vis selected to representv. - Formatting as a string: The decimal
d
vis formatted as a string, either in plain or in computerized scientific notation, depending on its value.
- Selection of a decimal: A well-defined
decimal d
A decimal is a number of the form d×10i for some (unique) integers d > 0 and i such that d is not a multiple of 10. These integers are the significand and the exponent, respectively, of the decimal. The length of the decimal is the (unique) integer n meeting 10n-1 ≤ d < 10n.
The decimal d
vfor a finite positivevis defined as follows:- Let R be the set of all decimals that round to
vaccording to the usual round-to-closest rule of IEEE 754 floating-point arithmetic. - Let m be the minimal length over all decimals in R.
- When m ≥ 2, let T be the set of all decimals in R with length m. Otherwise, let T be the set of all decimals in R with length 1 or 2.
- Define d
vas the decimal in T that is closest tov. Or if there are two such decimals in T, select the one with the even significand (there is exactly one).
The (uniquely) selected decimal d
vis then formatted.Let d, i and n be the significand, exponent and length of d
v, respectively. Further, let e = n + i - 1 and let d1…dn be the usual decimal expansion of the significand. Note that d1 ≠ 0 ≠ dn.- Case -3 ≤ e < 0:
d
vis formatted as0.0…0d1…dn, where there are exactly -(n + i) zeroes between the decimal point and d1. For example, 123 × 10-4 is formatted as0.0123. - Case 0 ≤ e < 7:
- Subcase i ≥ 0:
d
vis formatted as d1…dn0…0.0, where there are exactly i zeroes between dn and the decimal point. For example, 123 × 102 is formatted as12300.0. - Subcase i < 0:
d
vis formatted as d1…dn+i.dn+i+1…dn. There are exactly -i digits to the right of the decimal point. For example, 123 × 10-1 is formatted as12.3.
- Subcase i ≥ 0:
d
- Case e < -3 or e ≥ 7:
computerized scientific notation is used to format
d
v. Here e is formatted as byInteger.toString(int).- Subcase n = 1:
d
vis formatted as d1.0Ee. For example, 1 × 1023 is formatted as1.0E23. - Subcase n > 1:
d
vis formatted as d1.d2…dnEe. For example, 123 × 10-21 is formatted as1.23E-19.
- Subcase n = 1:
d
- Parameters:
v- thedoubleto be rendered.- Returns:
- a string rendering of the argument.
- Any NaN, whether quiet or signaling, is rendered as
-
toDecimalString
private java.lang.String toDecimalString(double v)
-
toDecimal
private int toDecimal(double v)
-
toDecimal
private int toDecimal(int q, long c, int dk)
-
rop
private static long rop(long g1, long g0, long cp)
-
toChars
private int toChars(long f, int e)
-
toChars1
private int toChars1(int h, int m, int l, int e)
-
toChars2
private int toChars2(int h, int m, int l, int e)
-
toChars3
private int toChars3(int h, int m, int l, int e)
-
lowDigits
private void lowDigits(int l)
-
append8Digits
private void append8Digits(int m)
-
removeTrailingZeroes
private void removeTrailingZeroes()
-
y
private int y(int a)
-
exponent
private void exponent(int e)
-
append
private void append(int c)
-
appendDigit
private void appendDigit(int d)
-
charsToString
private java.lang.String charsToString()
-
-