) Class.getPrimitiveClass("double");
/**
- * Returns a string representation of the {@code double}
- * argument. All characters mentioned below are ASCII characters.
+ * Returns a string rendering of the {@code double} argument.
+ *
+ * The characters of the result are all drawn from the ASCII set.
*
- * - If the argument is NaN, the result is the string
- * "{@code NaN}".
- *
- Otherwise, the result is a string that represents the sign and
- * magnitude (absolute value) of the argument. If the sign is negative,
- * the first character of the result is '{@code -}'
- * ({@code '\u005Cu002D'}); if the sign is positive, no sign character
- * appears in the result. As for the magnitude m:
+ *
- Any NaN, whether quiet or signaling, is rendered as
+ * {@code "NaN"}, regardless of the sign bit.
+ *
- The infinities +∞ and -∞ are rendered as
+ * {@code "Infinity"} and {@code "-Infinity"}, respectively.
+ *
- The positive and negative zeroes are rendered as
+ * {@code "0.0"} and {@code "-0.0"}, respectively.
+ *
- A finite negative {@code v} is rendered as the sign
+ * '{@code -}' followed by the rendering of the magnitude -{@code v}.
+ *
- A finite positive {@code v} is rendered in two stages:
*
- * - If m is infinity, it is represented by the characters
- * {@code "Infinity"}; thus, positive infinity produces the result
- * {@code "Infinity"} and negative infinity produces the result
- * {@code "-Infinity"}.
- *
- *
- If m is zero, it is represented by the characters
- * {@code "0.0"}; thus, negative zero produces the result
- * {@code "-0.0"} and positive zero produces the result
- * {@code "0.0"}.
- *
- *
- If m is greater than or equal to 10^{-3} but less
- * than 10^{7}, then it is represented as the integer part of
- * m, in decimal form with no leading zeroes, followed by
- * '{@code .}' ({@code '\u005Cu002E'}), followed by one or
- * more decimal digits representing the fractional part of m.
- *
- *
- If m is less than 10^{-3} or greater than or
- * equal to 10^{7}, then it is represented in so-called
- * "computerized scientific notation." Let n be the unique
- * integer such that 10^{n} ≤ m {@literal <}
- * 10^{n+1}; then let a be the
- * mathematically exact quotient of m and
- * 10^{n} so that 1 ≤ a {@literal <} 10. The
- * magnitude is then represented as the integer part of a,
- * as a single decimal digit, followed by '{@code .}'
- * ({@code '\u005Cu002E'}), followed by decimal digits
- * representing the fractional part of a, followed by the
- * letter '{@code E}' ({@code '\u005Cu0045'}), followed
- * by a representation of n as a decimal integer, as
- * produced by the method {@link Integer#toString(int)}.
+ *
- Selection of a decimal: A well-defined
+ * decimal d_{v} is selected
+ * to represent {@code v}.
+ *
- Formatting as a string: The decimal
+ * d_{v} is formatted as a string,
+ * either in plain or in computerized scientific notation,
+ * depending on its value.
*
*
- * How many digits must be printed for the fractional part of
- * m or a? There must be at least one digit to represent
- * the fractional part, and beyond that as many, but only as many, more
- * digits as are needed to uniquely distinguish the argument value from
- * adjacent values of type {@code double}. That is, suppose that
- * x is the exact mathematical value represented by the decimal
- * representation produced by this method for a finite nonzero argument
- * d. Then d must be the {@code double} value nearest
- * to x; or if two {@code double} values are equally close
- * to x, then d must be one of them and the least
- * significant bit of the significand of d must be {@code 0}.
*
- * To create localized string representations of a floating-point
- * value, use subclasses of {@link java.text.NumberFormat}.
+ *
A decimal is a number of the form
+ * d×10^{i}
+ * 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
+ * 10^{n-1} ≤ d < 10^{n}.
*
- * @param d the {@code double} to be converted.
- * @return a string representation of the argument.
+ *
The decimal d_{v}
+ * for a finite positive {@code v} is defined as follows:
+ *
+ * - Let R be the set of all decimals that round to {@code 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 d_{v} as
+ * the decimal in T that is closest to {@code 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 d_{v}
+ * is 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
+ * d_{1}…d_{n}
+ * be the usual decimal expansion of the significand.
+ * Note that d_{1} ≠ 0 ≠ d_{n}.
+ *
+ * - Case -3 ≤ e < 0:
+ * d_{v} is formatted as
+ *
0.0
…0
d_{1}…d_{n},
+ * where there are exactly -(n + i) zeroes between
+ * the decimal point and d_{1}.
+ * For example, 123 × 10^{-4} is formatted as
+ * {@code 0.0123}.
+ * - Case 0 ≤ e < 7:
+ *
+ * - Subcase i ≥ 0:
+ * d_{v} is formatted as
+ * d_{1}…d_{n}
0
…0.0
,
+ * where there are exactly i zeroes
+ * between d_{n} and the decimal point.
+ * For example, 123 × 10^{2} is formatted as
+ * {@code 12300.0}.
+ * - Subcase i < 0:
+ * d_{v} is formatted as
+ * d_{1}…d_{n+i}.d_{n+i+1}…d_{n}.
+ * There are exactly -i digits to the right of
+ * the decimal point.
+ * For example, 123 × 10^{-1} is formatted as
+ * {@code 12.3}.
+ *
+ * - Case e < -3 or e ≥ 7:
+ * computerized scientific notation is used to format
+ * d_{v}.
+ * Here e is formatted as by {@link Integer#toString(int)}.
+ *
+ * - Subcase n = 1:
+ * d_{v} is formatted as
+ * d_{1}
.0E
e.
+ * For example, 1 × 10^{23} is formatted as
+ * {@code 1.0E23}.
+ * - Subcase n > 1:
+ * d_{v} is formatted as
+ * d_{1}
.
d_{2}…d_{n}E
e.
+ * For example, 123 × 10^{-21} is formatted as
+ * {@code 1.23E-19}.
+ *
+ *
+ *
+ * @param v the {@code double} to be rendered.
+ * @return a string rendering of the argument.
*/
- public static String toString(double d) {
- return FloatingDecimal.toJavaFormatString(d);
+ public static String toString(double v) {
+ return DoubleToDecimal.toString(v);
}
/**