Preserve signed zero on roundtrip
This commit removes the previous mechanism of differentiating between "Debug" and "Display" formattings for the sign of -0 so as to comply with the IEEE 754 standard's requirements on external character sequences preserving various attributes of a floating point representation. In addition, numerous tests are fixed.
This commit is contained in:
parent
588cc644ad
commit
74db93ed2d
5 changed files with 102 additions and 200 deletions
|
@ -154,8 +154,7 @@ fn test_format_macro_interface() {
|
|||
t!(format!("{:+10.3e}", -1.2345e6f64), " -1.234e6");
|
||||
|
||||
// Float edge cases
|
||||
t!(format!("{}", -0.0), "0");
|
||||
t!(format!("{:?}", -0.0), "-0.0");
|
||||
t!(format!("{}", -0.0), "-0");
|
||||
t!(format!("{:?}", 0.0), "0.0");
|
||||
|
||||
// sign aware zero padding
|
||||
|
|
|
@ -54,21 +54,14 @@ where
|
|||
}
|
||||
|
||||
// Common code of floating point Debug and Display.
|
||||
fn float_to_decimal_common<T>(
|
||||
fmt: &mut Formatter<'_>,
|
||||
num: &T,
|
||||
negative_zero: bool,
|
||||
min_precision: usize,
|
||||
) -> Result
|
||||
fn float_to_decimal_common<T>(fmt: &mut Formatter<'_>, num: &T, min_precision: usize) -> Result
|
||||
where
|
||||
T: flt2dec::DecodableFloat,
|
||||
{
|
||||
let force_sign = fmt.sign_plus();
|
||||
let sign = match (force_sign, negative_zero) {
|
||||
(false, false) => flt2dec::Sign::Minus,
|
||||
(false, true) => flt2dec::Sign::MinusRaw,
|
||||
(true, false) => flt2dec::Sign::MinusPlus,
|
||||
(true, true) => flt2dec::Sign::MinusPlusRaw,
|
||||
let sign = match force_sign {
|
||||
false => flt2dec::Sign::Minus,
|
||||
true => flt2dec::Sign::MinusPlus,
|
||||
};
|
||||
|
||||
if let Some(precision) = fmt.precision {
|
||||
|
@ -156,14 +149,14 @@ macro_rules! floating {
|
|||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Debug for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
|
||||
float_to_decimal_common(fmt, self, true, 1)
|
||||
float_to_decimal_common(fmt, self, 1)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl Display for $ty {
|
||||
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
|
||||
float_to_decimal_common(fmt, self, false, 0)
|
||||
float_to_decimal_common(fmt, self, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -399,14 +399,10 @@ fn digits_to_exp_str<'a>(
|
|||
/// Sign formatting options.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum Sign {
|
||||
/// Prints `-` only for the negative non-zero values.
|
||||
Minus, // -inf -1 0 0 1 inf nan
|
||||
/// Prints `-` only for any negative values (including the negative zero).
|
||||
MinusRaw, // -inf -1 -0 0 1 inf nan
|
||||
/// Prints `-` for the negative non-zero values, or `+` otherwise.
|
||||
MinusPlus, // -inf -1 +0 +0 +1 +inf nan
|
||||
/// Prints `-` for any negative values (including the negative zero), or `+` otherwise.
|
||||
MinusPlusRaw, // -inf -1 -0 +0 +1 +inf nan
|
||||
/// Prints `-` for any negative value.
|
||||
Minus, // -inf -1 -0 0 1 inf nan
|
||||
/// Prints `-` for any negative value, or `+` otherwise.
|
||||
MinusPlus, // -inf -1 -0 +0 +1 +inf nan
|
||||
}
|
||||
|
||||
/// Returns the static byte string corresponding to the sign to be formatted.
|
||||
|
@ -414,30 +410,14 @@ pub enum Sign {
|
|||
fn determine_sign(sign: Sign, decoded: &FullDecoded, negative: bool) -> &'static str {
|
||||
match (*decoded, sign) {
|
||||
(FullDecoded::Nan, _) => "",
|
||||
(FullDecoded::Zero, Sign::Minus) => "",
|
||||
(FullDecoded::Zero, Sign::MinusRaw) => {
|
||||
(_, Sign::Minus) => {
|
||||
if negative {
|
||||
"-"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
(FullDecoded::Zero, Sign::MinusPlus) => "+",
|
||||
(FullDecoded::Zero, Sign::MinusPlusRaw) => {
|
||||
if negative {
|
||||
"-"
|
||||
} else {
|
||||
"+"
|
||||
}
|
||||
}
|
||||
(_, Sign::Minus | Sign::MinusRaw) => {
|
||||
if negative {
|
||||
"-"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
(_, Sign::MinusPlus | Sign::MinusPlusRaw) => {
|
||||
(_, Sign::MinusPlus) => {
|
||||
if negative {
|
||||
"-"
|
||||
} else {
|
||||
|
|
|
@ -514,51 +514,38 @@ where
|
|||
let f = &mut f_;
|
||||
|
||||
assert_eq!(to_string(f, 0.0, Minus, 0), "0");
|
||||
assert_eq!(to_string(f, 0.0, MinusRaw, 0), "0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, 0), "0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, 0), "+0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlusRaw, 0), "+0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 0), "0");
|
||||
assert_eq!(to_string(f, -0.0, MinusRaw, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 0), "+0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 0), "-0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, 1), "0.0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, 1), "0.0");
|
||||
assert_eq!(to_string(f, 0.0, MinusRaw, 1), "0.0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, 1), "+0.0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlusRaw, 1), "+0.0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 8), "0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, MinusRaw, 8), "-0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 8), "+0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 8), "-0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 8), "-0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 8), "-0.00000000");
|
||||
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, Minus, 0), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusRaw, 0), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, Minus, 0), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlus, 0), "+inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlusRaw, 0), "+inf");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, Minus, 0), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusRaw, 1), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlus, 8), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlusRaw, 64), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, Minus, 1), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlus, 64), "NaN");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, Minus, 0), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusRaw, 1), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlus, 8), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlusRaw, 64), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, Minus, 1), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlus, 64), "-inf");
|
||||
|
||||
assert_eq!(to_string(f, 3.14, Minus, 0), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusRaw, 0), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 0), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 0), "+3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlusRaw, 0), "+3.14");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 0), "-3.14");
|
||||
assert_eq!(to_string(f, -3.14, MinusRaw, 0), "-3.14");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 0), "-3.14");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, 0), "-3.14");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlusRaw, 0), "-3.14");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 1), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusRaw, 2), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 3), "+3.140");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlusRaw, 4), "+3.1400");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 2), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 4), "+3.1400");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 8), "-3.14000000");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 8), "-3.14000000");
|
||||
assert_eq!(to_string(f, -3.14, MinusRaw, 8), "-3.14000000");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, 8), "-3.14000000");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlusRaw, 8), "-3.14000000");
|
||||
|
||||
assert_eq!(to_string(f, 7.5e-11, Minus, 0), "0.000000000075");
|
||||
assert_eq!(to_string(f, 7.5e-11, Minus, 3), "0.000000000075");
|
||||
|
@ -615,68 +602,48 @@ where
|
|||
let f = &mut f_;
|
||||
|
||||
assert_eq!(to_string(f, 0.0, Minus, (-4, 16), false), "0");
|
||||
assert_eq!(to_string(f, 0.0, MinusRaw, (-4, 16), false), "0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, (-4, 16), false), "0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, (-4, 16), false), "+0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlusRaw, (-4, 16), false), "+0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, (-4, 16), false), "0");
|
||||
assert_eq!(to_string(f, -0.0, MinusRaw, (-4, 16), false), "-0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, (-4, 16), false), "+0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlusRaw, (-4, 16), false), "-0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, (-4, 16), false), "-0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, (-4, 16), false), "-0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, (0, 0), true), "0E0");
|
||||
assert_eq!(to_string(f, 0.0, MinusRaw, (0, 0), false), "0e0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, (-9, -5), true), "+0E0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlusRaw, (5, 9), false), "+0e0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, (0, 0), true), "0E0");
|
||||
assert_eq!(to_string(f, -0.0, MinusRaw, (0, 0), false), "-0e0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, (-9, -5), true), "+0E0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlusRaw, (5, 9), false), "-0e0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, (0, 0), false), "0e0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, (5, 9), false), "+0e0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, (0, 0), true), "-0E0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, (5, 9), false), "-0e0");
|
||||
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, Minus, (-4, 16), false), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusRaw, (-4, 16), true), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlus, (-4, 16), false), "+inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlusRaw, (-4, 16), true), "+inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, Minus, (-4, 16), true), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlus, (-4, 16), true), "+inf");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, Minus, (0, 0), false), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusRaw, (0, 0), true), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlus, (-9, -5), false), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlusRaw, (5, 9), true), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, Minus, (0, 0), true), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlus, (5, 9), true), "NaN");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, Minus, (0, 0), false), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusRaw, (0, 0), true), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlus, (-9, -5), false), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlusRaw, (5, 9), true), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, Minus, (0, 0), true), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlus, (5, 9), true), "-inf");
|
||||
|
||||
assert_eq!(to_string(f, 3.14, Minus, (-4, 16), false), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusRaw, (-4, 16), false), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, (-4, 16), false), "+3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlusRaw, (-4, 16), false), "+3.14");
|
||||
assert_eq!(to_string(f, -3.14, Minus, (-4, 16), false), "-3.14");
|
||||
assert_eq!(to_string(f, -3.14, MinusRaw, (-4, 16), false), "-3.14");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, (-4, 16), false), "-3.14");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlusRaw, (-4, 16), false), "-3.14");
|
||||
assert_eq!(to_string(f, 3.14, Minus, (0, 0), true), "3.14E0");
|
||||
assert_eq!(to_string(f, 3.14, MinusRaw, (0, 0), false), "3.14e0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, (-9, -5), true), "+3.14E0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlusRaw, (5, 9), false), "+3.14e0");
|
||||
assert_eq!(to_string(f, 3.14, Minus, (0, 0), false), "3.14e0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, (5, 9), false), "+3.14e0");
|
||||
assert_eq!(to_string(f, -3.14, Minus, (0, 0), true), "-3.14E0");
|
||||
assert_eq!(to_string(f, -3.14, MinusRaw, (0, 0), false), "-3.14e0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, (-9, -5), true), "-3.14E0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlusRaw, (5, 9), false), "-3.14e0");
|
||||
assert_eq!(to_string(f, -3.14, Minus, (0, 0), false), "-3.14e0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, (5, 9), false), "-3.14e0");
|
||||
|
||||
assert_eq!(to_string(f, 0.1, Minus, (-4, 16), false), "0.1");
|
||||
assert_eq!(to_string(f, 0.1, MinusRaw, (-4, 16), false), "0.1");
|
||||
assert_eq!(to_string(f, 0.1, Minus, (-4, 16), false), "0.1");
|
||||
assert_eq!(to_string(f, 0.1, MinusPlus, (-4, 16), false), "+0.1");
|
||||
assert_eq!(to_string(f, 0.1, MinusPlusRaw, (-4, 16), false), "+0.1");
|
||||
assert_eq!(to_string(f, -0.1, Minus, (-4, 16), false), "-0.1");
|
||||
assert_eq!(to_string(f, -0.1, MinusRaw, (-4, 16), false), "-0.1");
|
||||
assert_eq!(to_string(f, -0.1, MinusPlus, (-4, 16), false), "-0.1");
|
||||
assert_eq!(to_string(f, -0.1, MinusPlusRaw, (-4, 16), false), "-0.1");
|
||||
assert_eq!(to_string(f, 0.1, Minus, (0, 0), true), "1E-1");
|
||||
assert_eq!(to_string(f, 0.1, MinusRaw, (0, 0), false), "1e-1");
|
||||
assert_eq!(to_string(f, 0.1, MinusPlus, (-9, -5), true), "+1E-1");
|
||||
assert_eq!(to_string(f, 0.1, MinusPlusRaw, (5, 9), false), "+1e-1");
|
||||
assert_eq!(to_string(f, 0.1, Minus, (0, 0), false), "1e-1");
|
||||
assert_eq!(to_string(f, 0.1, MinusPlus, (5, 9), false), "+1e-1");
|
||||
assert_eq!(to_string(f, -0.1, Minus, (0, 0), true), "-1E-1");
|
||||
assert_eq!(to_string(f, -0.1, MinusRaw, (0, 0), false), "-1e-1");
|
||||
assert_eq!(to_string(f, -0.1, MinusPlus, (-9, -5), true), "-1E-1");
|
||||
assert_eq!(to_string(f, -0.1, MinusPlusRaw, (5, 9), false), "-1e-1");
|
||||
assert_eq!(to_string(f, -0.1, Minus, (0, 0), false), "-1e-1");
|
||||
assert_eq!(to_string(f, -0.1, MinusPlus, (5, 9), false), "-1e-1");
|
||||
|
||||
assert_eq!(to_string(f, 7.5e-11, Minus, (-4, 16), false), "7.5e-11");
|
||||
assert_eq!(to_string(f, 7.5e-11, Minus, (-11, 10), false), "0.000000000075");
|
||||
|
@ -734,68 +701,51 @@ where
|
|||
let f = &mut f_;
|
||||
|
||||
assert_eq!(to_string(f, 0.0, Minus, 1, true), "0E0");
|
||||
assert_eq!(to_string(f, 0.0, MinusRaw, 1, false), "0e0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, 1, true), "+0E0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlusRaw, 1, false), "+0e0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 1, true), "0E0");
|
||||
assert_eq!(to_string(f, -0.0, MinusRaw, 1, false), "-0e0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 1, true), "+0E0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 1, false), "-0e0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, 1, false), "0e0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, 1, false), "+0e0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 1, true), "-0E0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 1, false), "-0e0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, 2, true), "0.0E0");
|
||||
assert_eq!(to_string(f, 0.0, MinusRaw, 2, false), "0.0e0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, 2, true), "+0.0E0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlusRaw, 2, false), "+0.0e0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 8, true), "0.0000000E0");
|
||||
assert_eq!(to_string(f, -0.0, MinusRaw, 8, false), "-0.0000000e0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 8, true), "+0.0000000E0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 8, false), "-0.0000000e0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, 2, false), "0.0e0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, 2, false), "+0.0e0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 8, false), "-0.0000000e0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 8, false), "-0.0000000e0");
|
||||
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, Minus, 1, false), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusRaw, 1, true), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlus, 1, false), "+inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlusRaw, 1, true), "+inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, Minus, 1, true), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlus, 1, true), "+inf");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, Minus, 8, false), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusRaw, 8, true), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlus, 8, false), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlusRaw, 8, true), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, Minus, 8, true), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlus, 8, true), "NaN");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, Minus, 64, false), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusRaw, 64, true), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlus, 64, false), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlusRaw, 64, true), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, Minus, 64, true), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlus, 64, true), "-inf");
|
||||
|
||||
assert_eq!(to_string(f, 3.14, Minus, 1, true), "3E0");
|
||||
assert_eq!(to_string(f, 3.14, MinusRaw, 1, false), "3e0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 1, true), "+3E0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlusRaw, 1, false), "+3e0");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 1, false), "3e0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 1, false), "+3e0");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 2, true), "-3.1E0");
|
||||
assert_eq!(to_string(f, -3.14, MinusRaw, 2, false), "-3.1e0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, 2, true), "-3.1E0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlusRaw, 2, false), "-3.1e0");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 2, false), "-3.1e0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, 2, false), "-3.1e0");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 3, true), "3.14E0");
|
||||
assert_eq!(to_string(f, 3.14, MinusRaw, 3, false), "3.14e0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 3, true), "+3.14E0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlusRaw, 3, false), "+3.14e0");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 3, false), "3.14e0");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 3, false), "+3.14e0");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 4, true), "-3.140E0");
|
||||
assert_eq!(to_string(f, -3.14, MinusRaw, 4, false), "-3.140e0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, 4, true), "-3.140E0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlusRaw, 4, false), "-3.140e0");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 4, false), "-3.140e0");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, 4, false), "-3.140e0");
|
||||
|
||||
assert_eq!(to_string(f, 0.195, Minus, 1, false), "2e-1");
|
||||
assert_eq!(to_string(f, 0.195, MinusRaw, 1, true), "2E-1");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlus, 1, false), "+2e-1");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlusRaw, 1, true), "+2E-1");
|
||||
assert_eq!(to_string(f, 0.195, Minus, 1, true), "2E-1");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlus, 1, true), "+2E-1");
|
||||
assert_eq!(to_string(f, -0.195, Minus, 2, false), "-2.0e-1");
|
||||
assert_eq!(to_string(f, -0.195, MinusRaw, 2, true), "-2.0E-1");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlus, 2, false), "-2.0e-1");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlusRaw, 2, true), "-2.0E-1");
|
||||
assert_eq!(to_string(f, -0.195, Minus, 2, true), "-2.0E-1");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlus, 2, true), "-2.0E-1");
|
||||
assert_eq!(to_string(f, 0.195, Minus, 3, false), "1.95e-1");
|
||||
assert_eq!(to_string(f, 0.195, MinusRaw, 3, true), "1.95E-1");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlus, 3, false), "+1.95e-1");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlusRaw, 3, true), "+1.95E-1");
|
||||
assert_eq!(to_string(f, 0.195, Minus, 3, true), "1.95E-1");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlus, 3, true), "+1.95E-1");
|
||||
assert_eq!(to_string(f, -0.195, Minus, 4, false), "-1.950e-1");
|
||||
assert_eq!(to_string(f, -0.195, MinusRaw, 4, true), "-1.950E-1");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlus, 4, false), "-1.950e-1");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlusRaw, 4, true), "-1.950E-1");
|
||||
assert_eq!(to_string(f, -0.195, Minus, 4, true), "-1.950E-1");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlus, 4, true), "-1.950E-1");
|
||||
|
||||
assert_eq!(to_string(f, 9.5, Minus, 1, false), "1e1");
|
||||
assert_eq!(to_string(f, 9.5, Minus, 2, false), "9.5e0");
|
||||
|
@ -1007,68 +957,48 @@ where
|
|||
let f = &mut f_;
|
||||
|
||||
assert_eq!(to_string(f, 0.0, Minus, 0), "0");
|
||||
assert_eq!(to_string(f, 0.0, MinusRaw, 0), "0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, 0), "+0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlusRaw, 0), "+0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 0), "0");
|
||||
assert_eq!(to_string(f, -0.0, MinusRaw, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 0), "+0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 0), "-0");
|
||||
assert_eq!(to_string(f, 0.0, Minus, 1), "0.0");
|
||||
assert_eq!(to_string(f, 0.0, MinusRaw, 1), "0.0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlus, 1), "+0.0");
|
||||
assert_eq!(to_string(f, 0.0, MinusPlusRaw, 1), "+0.0");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 8), "0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, MinusRaw, 8), "-0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 8), "+0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 8), "-0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, Minus, 8), "-0.00000000");
|
||||
assert_eq!(to_string(f, -0.0, MinusPlus, 8), "-0.00000000");
|
||||
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, Minus, 0), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusRaw, 1), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlus, 8), "+inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlusRaw, 64), "+inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, Minus, 1), "inf");
|
||||
assert_eq!(to_string(f, 1.0 / 0.0, MinusPlus, 64), "+inf");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, Minus, 0), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusRaw, 1), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlus, 8), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlusRaw, 64), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, Minus, 1), "NaN");
|
||||
assert_eq!(to_string(f, 0.0 / 0.0, MinusPlus, 64), "NaN");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, Minus, 0), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusRaw, 1), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlus, 8), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlusRaw, 64), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, Minus, 1), "-inf");
|
||||
assert_eq!(to_string(f, -1.0 / 0.0, MinusPlus, 64), "-inf");
|
||||
|
||||
assert_eq!(to_string(f, 3.14, Minus, 0), "3");
|
||||
assert_eq!(to_string(f, 3.14, MinusRaw, 0), "3");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 0), "3");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 0), "+3");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlusRaw, 0), "+3");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 0), "-3");
|
||||
assert_eq!(to_string(f, -3.14, MinusRaw, 0), "-3");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 0), "-3");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, 0), "-3");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlusRaw, 0), "-3");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 1), "3.1");
|
||||
assert_eq!(to_string(f, 3.14, MinusRaw, 2), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 3), "+3.140");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlusRaw, 4), "+3.1400");
|
||||
assert_eq!(to_string(f, 3.14, Minus, 2), "3.14");
|
||||
assert_eq!(to_string(f, 3.14, MinusPlus, 4), "+3.1400");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 8), "-3.14000000");
|
||||
assert_eq!(to_string(f, -3.14, Minus, 8), "-3.14000000");
|
||||
assert_eq!(to_string(f, -3.14, MinusRaw, 8), "-3.14000000");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlus, 8), "-3.14000000");
|
||||
assert_eq!(to_string(f, -3.14, MinusPlusRaw, 8), "-3.14000000");
|
||||
|
||||
assert_eq!(to_string(f, 0.195, Minus, 0), "0");
|
||||
assert_eq!(to_string(f, 0.195, MinusRaw, 0), "0");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlus, 0), "+0");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlusRaw, 0), "+0");
|
||||
assert_eq!(to_string(f, -0.195, Minus, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.195, MinusRaw, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.195, Minus, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlus, 0), "-0");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlusRaw, 0), "-0");
|
||||
assert_eq!(to_string(f, 0.195, Minus, 1), "0.2");
|
||||
assert_eq!(to_string(f, 0.195, MinusRaw, 2), "0.20");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlus, 3), "+0.195");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlusRaw, 4), "+0.1950");
|
||||
assert_eq!(to_string(f, 0.195, Minus, 2), "0.20");
|
||||
assert_eq!(to_string(f, 0.195, MinusPlus, 4), "+0.1950");
|
||||
assert_eq!(to_string(f, -0.195, Minus, 5), "-0.19500");
|
||||
assert_eq!(to_string(f, -0.195, MinusRaw, 6), "-0.195000");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlus, 7), "-0.1950000");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlusRaw, 8), "-0.19500000");
|
||||
assert_eq!(to_string(f, -0.195, Minus, 6), "-0.195000");
|
||||
assert_eq!(to_string(f, -0.195, MinusPlus, 8), "-0.19500000");
|
||||
|
||||
assert_eq!(to_string(f, 999.5, Minus, 0), "1000");
|
||||
assert_eq!(to_string(f, 999.5, Minus, 1), "999.5");
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
}
|
||||
|
||||
bb2: {
|
||||
discriminant(_6) = 2; // scope 1 at $DIR/funky_arms.rs:21:17: 21:41
|
||||
discriminant(_6) = 1; // scope 1 at $DIR/funky_arms.rs:21:17: 21:41
|
||||
goto -> bb4; // scope 1 at $DIR/funky_arms.rs:19:16: 22:6
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue