Top Description Fields Constructors Methods
com.fasterxml.jackson.core.io.schubfach

public final Class FloatToDecimal

extends Object
Class Inheritance
Static Imports
com.fasterxml.jackson.core.io.schubfach.MathUtils.flog10pow2, .MathUtils.flog10threeQuartersPow2, .MathUtils.flog2pow10, .MathUtils.g1, .MathUtils.multiplyHigh, .MathUtils.pow10, java.lang.Float.floatToRawIntBits, .Integer.numberOfLeadingZeros

This class exposes a method to render a float as a string.
Author
Raffaello Giulietti

Field Summary

Modifier and TypeField and Description
private static final int
private final byte[]
private static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
H

private int
pack-priv static final int
pack-priv static final int
private static final int
private static final long
public final int
private static final int
private static final int
private static final int
private static final int
pack-priv static final int
P

private static final int
private static final int
pack-priv static final int
pack-priv static final int
private static final int
private static final int
W

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private void
append(int c)

private void
private void
appendDigit(int d)

private String
private void
exponent(int e)

private void
private static int
rop(long g, long cp)

private int
toChars(int f, int e)

private int
toChars1(int h, int l, int e)

private int
toChars2(int h, int l, int e)

private int
toChars3(int h, int l, int e)

private int
toDecimal(float v)

private int
toDecimal(int q, int c, int dk)

private String
toDecimalString(float v)

public static String

Returns:

a string rendering of the argument.
toString
(float
the float to be rendered.
v
)

Returns a string rendering of the float argument.

private int
y(int a)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BQ_MASKback to summary
private static final int BQ_MASK
bytesback to summary
private final byte[] bytes
C_MINback to summary
private static final int C_MIN
C_TINYback to summary
pack-priv static final int C_TINY
E_MAXback to summary
pack-priv static final int E_MAX
E_MINback to summary
pack-priv static final int E_MIN
Hback to summary
pack-priv static final int H
indexback to summary
private int index
K_MAXback to summary
pack-priv static final int K_MAX
K_MINback to summary
pack-priv static final int K_MIN
MASK_28back to summary
private static final int MASK_28
MASK_32back to summary
private static final long MASK_32
MAX_CHARSback to summary
public final int MAX_CHARS
MINUS_INFback to summary
private static final int MINUS_INF
MINUS_ZEROback to summary
private static final int MINUS_ZERO
NANback to summary
private static final int NAN
NON_SPECIALback to summary
private static final int NON_SPECIAL
Pback to summary
pack-priv static final int P
PLUS_INFback to summary
private static final int PLUS_INF
PLUS_ZEROback to summary
private static final int PLUS_ZERO
Q_MAXback to summary
pack-priv static final int Q_MAX
Q_MINback to summary
pack-priv static final int Q_MIN
T_MASKback to summary
private static final int T_MASK
Wback to summary
private static final int W

Constructor Detail

FloatToDecimalback to summary
private FloatToDecimal()

Method Detail

appendback to summary
private void append(int c)
append8Digitsback to summary
private void append8Digits(int m)
appendDigitback to summary
private void appendDigit(int d)
charsToStringback to summary
private String charsToString()
Annotations
@SuppressWarnings:deprecation
exponentback to summary
private void exponent(int e)
removeTrailingZeroesback to summary
private void removeTrailingZeroes()
ropback to summary
private static int rop(long g, long cp)
toCharsback to summary
private int toChars(int f, int e)
toChars1back to summary
private int toChars1(int h, int l, int e)
toChars2back to summary
private int toChars2(int h, int l, int e)
toChars3back to summary
private int toChars3(int h, int l, int e)
toDecimalback to summary
private int toDecimal(float v)
toDecimalback to summary
private int toDecimal(int q, int c, int dk)
toDecimalStringback to summary
private String toDecimalString(float v)
toStringback to summary
public static String toString(float v)

Returns a string rendering of the float argument.

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 v is rendered as the sign '-' followed by the rendering of the magnitude -v.
  • A finite positive v is rendered in two stages:
    • Selection of a decimal: A well-defined decimal dv is selected to represent v.
    • Formatting as a string: The decimal dv is formatted as a string, either in plain or in computerized scientific notation, depending on its value.

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 dv for a finite positive v is defined as follows:

  • Let R be the set of all decimals that round to v according 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 dv as the decimal in T that is closest to v. Or if there are two such decimals in T, select the one with the even significand (there is exactly one).

The (uniquely) selected decimal dv is then formatted.

Let d, i and n be the significand, exponent and length of dv, 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: dv is formatted as 0.0…0d1…dn, where there are exactly -(n + i) zeroes between the decimal point and d1. For example, 123 × 10-4 is formatted as 0.0123.
  • Case 0 ≤ e < 7:
    • Subcase i ≥ 0: dv is formatted as d1…dn0…0.0, where there are exactly i zeroes between dn and the decimal point. For example, 123 × 102 is formatted as 12300.0.
    • Subcase i < 0: dv is 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 as 12.3.
  • Case e < -3 or e ≥ 7: computerized scientific notation is used to format dv. Here e is formatted as by Integer#toString(int).
    • Subcase n = 1: dv is formatted as d1.0Ee. For example, 1 × 1023 is formatted as 1.0E23.
    • Subcase n > 1: dv is formatted as d1.d2…dnEe. For example, 123 × 10-21 is formatted as 1.23E-19.
Parameters
v:float

the float to be rendered.

Returns:String

a string rendering of the argument.

yback to summary
private int y(int a)