Skip to content

Commit

Permalink
core: tweaked flt2dec to match the casing of the older formatting code.
Browse files Browse the repository at this point in the history
  • Loading branch information
lifthrasiir committed May 6, 2015
1 parent 5aa9f38 commit f9bfda0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
36 changes: 18 additions & 18 deletions src/libcore/num/flt2dec/mod.rs
Expand Up @@ -396,10 +396,10 @@ fn determine_sign(sign: Sign, decoded: &FullDecoded, negative: bool) -> &'static

/// Formats given floating point number into the decimal form with at least
/// given number of fractional digits. The result is stored to the supplied parts
/// array while utilizing given byte buffer as a scratch. `upper` is only used to
/// determine the case of non-finite values, i.e. `inf` and `nan`. The first part
/// to be rendered is always a `Part::Sign` (which can be an empty string
/// if no sign is rendered).
/// array while utilizing given byte buffer as a scratch. `upper` is currently
/// unused but left for the future decision to change the case of non-finite values,
/// i.e. `inf` and `nan`. The first part to be rendered is always a `Part::Sign`
/// (which can be an empty string if no sign is rendered).
///
/// `format_shortest` should be the underlying digit-generation function.
/// You probably would want `strategy::grisu::format_shortest` for this.
Expand All @@ -413,7 +413,7 @@ fn determine_sign(sign: Sign, decoded: &FullDecoded, negative: bool) -> &'static
/// There should be at least 5 parts available, due to the worst case like
/// `[+][0.][0000][45][0000]` with `frac_digits = 10`.
pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T,
sign: Sign, frac_digits: usize, upper: bool,
sign: Sign, frac_digits: usize, _upper: bool,
buf: &'a mut [u8], parts: &'a mut [Part<'a>]) -> Formatted<'a>
where T: DecodableFloat, F: FnMut(&Decoded, &mut [u8]) -> (usize, i16) {
assert!(parts.len() >= 4);
Expand All @@ -423,11 +423,11 @@ pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T,
let sign = determine_sign(sign, &full_decoded, negative);
match full_decoded {
FullDecoded::Nan => {
parts[0] = Part::Copy(if upper { b"NAN" } else { b"nan" });
parts[0] = Part::Copy(b"NaN");
Formatted { sign: sign, parts: &parts[..1] }
}
FullDecoded::Infinite => {
parts[0] = Part::Copy(if upper { b"INF" } else { b"inf" });
parts[0] = Part::Copy(b"inf");
Formatted { sign: sign, parts: &parts[..1] }
}
FullDecoded::Zero => {
Expand Down Expand Up @@ -479,11 +479,11 @@ pub fn to_shortest_exp_str<'a, T, F>(mut format_shortest: F, v: T,
let sign = determine_sign(sign, &full_decoded, negative);
match full_decoded {
FullDecoded::Nan => {
parts[0] = Part::Copy(if upper { b"NAN" } else { b"nan" });
parts[0] = Part::Copy(b"NaN");
Formatted { sign: sign, parts: &parts[..1] }
}
FullDecoded::Infinite => {
parts[0] = Part::Copy(if upper { b"INF" } else { b"inf" });
parts[0] = Part::Copy(b"inf");
Formatted { sign: sign, parts: &parts[..1] }
}
FullDecoded::Zero => {
Expand Down Expand Up @@ -557,11 +557,11 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
let sign = determine_sign(sign, &full_decoded, negative);
match full_decoded {
FullDecoded::Nan => {
parts[0] = Part::Copy(if upper { b"NAN" } else { b"nan" });
parts[0] = Part::Copy(b"NaN");
Formatted { sign: sign, parts: &parts[..1] }
}
FullDecoded::Infinite => {
parts[0] = Part::Copy(if upper { b"INF" } else { b"inf" });
parts[0] = Part::Copy(b"inf");
Formatted { sign: sign, parts: &parts[..1] }
}
FullDecoded::Zero => {
Expand Down Expand Up @@ -589,10 +589,10 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,

/// Formats given floating point number into the decimal form with exactly
/// given number of fractional digits. The result is stored to the supplied parts
/// array while utilizing given byte buffer as a scratch. `upper` is only used to
/// determine the case of non-finite values, i.e. `inf` and `nan`. The first part
/// to be rendered is always a `Part::Sign` (which can be an empty string
/// if no sign is rendered).
/// array while utilizing given byte buffer as a scratch. `upper` is currently
/// unused but left for the future decision to change the case of non-finite values,
/// i.e. `inf` and `nan`. The first part to be rendered is always a `Part::Sign`
/// (which can be an empty string if no sign is rendered).
///
/// `format_exact` should be the underlying digit-generation function.
/// You probably would want `strategy::grisu::format_exact` for this.
Expand All @@ -603,7 +603,7 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
/// There should be at least 5 parts available, due to the worst case like
/// `[+][0.][0000][45][0000]` with `frac_digits = 10`.
pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
sign: Sign, frac_digits: usize, upper: bool,
sign: Sign, frac_digits: usize, _upper: bool,
buf: &'a mut [u8], parts: &'a mut [Part<'a>]) -> Formatted<'a>
where T: DecodableFloat, F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) {
assert!(parts.len() >= 4);
Expand All @@ -612,11 +612,11 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
let sign = determine_sign(sign, &full_decoded, negative);
match full_decoded {
FullDecoded::Nan => {
parts[0] = Part::Copy(if upper { b"NAN" } else { b"nan" });
parts[0] = Part::Copy(b"NaN");
Formatted { sign: sign, parts: &parts[..1] }
}
FullDecoded::Infinite => {
parts[0] = Part::Copy(if upper { b"INF" } else { b"inf" });
parts[0] = Part::Copy(b"inf");
Formatted { sign: sign, parts: &parts[..1] }
}
FullDecoded::Zero => {
Expand Down
64 changes: 32 additions & 32 deletions src/libcoretest/num/flt2dec/mod.rs
Expand Up @@ -544,17 +544,17 @@ pub fn to_shortest_str_test<F>(mut f_: F)
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 8, true), "-0.00000000");

assert_eq!(to_string(f, 1.0/0.0, Minus, 0, false), "inf");
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 0, true), "INF");
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 0, true), "inf");
assert_eq!(to_string(f, 1.0/0.0, MinusPlus, 0, false), "+inf");
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 0, true), "+INF");
assert_eq!(to_string(f, 0.0/0.0, Minus, 0, false), "nan");
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 1, 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, 64, true), "NAN");
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 0, true), "+inf");
assert_eq!(to_string(f, 0.0/0.0, Minus, 0, false), "NaN");
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 1, 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, 64, true), "NaN");
assert_eq!(to_string(f, -1.0/0.0, Minus, 0, false), "-inf");
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 1, true), "-INF");
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 1, true), "-inf");
assert_eq!(to_string(f, -1.0/0.0, MinusPlus, 8, false), "-inf");
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-INF");
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-inf");

assert_eq!(to_string(f, 3.14, Minus, 0, false), "3.14");
assert_eq!(to_string(f, 3.14, MinusRaw, 0, false), "3.14");
Expand Down Expand Up @@ -638,17 +638,17 @@ pub fn to_shortest_exp_str_test<F>(mut f_: F)
assert_eq!(to_string(f, -0.0, MinusPlusRaw, ( 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, 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, 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, 1.0/0.0, MinusPlusRaw, (-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, -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, 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, MinusPlusRaw, ( 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");
Expand Down Expand Up @@ -752,17 +752,17 @@ pub fn to_exact_exp_str_test<F>(mut f_: F)
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 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, 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, 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, 1.0/0.0, MinusPlusRaw, 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, -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, 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, MinusPlusRaw, 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");
Expand Down Expand Up @@ -973,17 +973,17 @@ pub fn to_exact_fixed_str_test<F>(mut f_: F)
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 8, true), "-0.00000000");

assert_eq!(to_string(f, 1.0/0.0, Minus, 0, false), "inf");
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 1, true), "INF");
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 1, true), "inf");
assert_eq!(to_string(f, 1.0/0.0, MinusPlus, 8, false), "+inf");
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 64, true), "+INF");
assert_eq!(to_string(f, 0.0/0.0, Minus, 0, false), "nan");
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 1, 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, 64, true), "NAN");
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 64, true), "+inf");
assert_eq!(to_string(f, 0.0/0.0, Minus, 0, false), "NaN");
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 1, 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, 64, true), "NaN");
assert_eq!(to_string(f, -1.0/0.0, Minus, 0, false), "-inf");
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 1, true), "-INF");
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 1, true), "-inf");
assert_eq!(to_string(f, -1.0/0.0, MinusPlus, 8, false), "-inf");
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-INF");
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-inf");

assert_eq!(to_string(f, 3.14, Minus, 0, false), "3");
assert_eq!(to_string(f, 3.14, MinusRaw, 0, false), "3");
Expand Down

0 comments on commit f9bfda0

Please sign in to comment.