Skip to content

Commit 762e82e

Browse files
committed
core: tweaked flt2dec to match the casing of the older formatting code.
1 parent 493b036 commit 762e82e

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

src/libcore/num/flt2dec/mod.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,10 @@ fn determine_sign(sign: Sign, decoded: &FullDecoded, negative: bool) -> &'static
396396

397397
/// Formats given floating point number into the decimal form with at least
398398
/// given number of fractional digits. The result is stored to the supplied parts
399-
/// array while utilizing given byte buffer as a scratch. `upper` is only used to
400-
/// determine the case of non-finite values, i.e. `inf` and `nan`. The first part
401-
/// to be rendered is always a `Part::Sign` (which can be an empty string
402-
/// if no sign is rendered).
399+
/// array while utilizing given byte buffer as a scratch. `upper` is currently
400+
/// unused but left for the future decision to change the case of non-finite values,
401+
/// i.e. `inf` and `nan`. The first part to be rendered is always a `Part::Sign`
402+
/// (which can be an empty string if no sign is rendered).
403403
///
404404
/// `format_shortest` should be the underlying digit-generation function.
405405
/// You probably would want `strategy::grisu::format_shortest` for this.
@@ -413,7 +413,7 @@ fn determine_sign(sign: Sign, decoded: &FullDecoded, negative: bool) -> &'static
413413
/// There should be at least 5 parts available, due to the worst case like
414414
/// `[+][0.][0000][45][0000]` with `frac_digits = 10`.
415415
pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T,
416-
sign: Sign, frac_digits: usize, upper: bool,
416+
sign: Sign, frac_digits: usize, _upper: bool,
417417
buf: &'a mut [u8], parts: &'a mut [Part<'a>]) -> Formatted<'a>
418418
where T: DecodableFloat, F: FnMut(&Decoded, &mut [u8]) -> (usize, i16) {
419419
assert!(parts.len() >= 4);
@@ -423,11 +423,11 @@ pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T,
423423
let sign = determine_sign(sign, &full_decoded, negative);
424424
match full_decoded {
425425
FullDecoded::Nan => {
426-
parts[0] = Part::Copy(if upper { b"NAN" } else { b"nan" });
426+
parts[0] = Part::Copy(b"NaN");
427427
Formatted { sign: sign, parts: &parts[..1] }
428428
}
429429
FullDecoded::Infinite => {
430-
parts[0] = Part::Copy(if upper { b"INF" } else { b"inf" });
430+
parts[0] = Part::Copy(b"inf");
431431
Formatted { sign: sign, parts: &parts[..1] }
432432
}
433433
FullDecoded::Zero => {
@@ -479,11 +479,11 @@ pub fn to_shortest_exp_str<'a, T, F>(mut format_shortest: F, v: T,
479479
let sign = determine_sign(sign, &full_decoded, negative);
480480
match full_decoded {
481481
FullDecoded::Nan => {
482-
parts[0] = Part::Copy(if upper { b"NAN" } else { b"nan" });
482+
parts[0] = Part::Copy(b"NaN");
483483
Formatted { sign: sign, parts: &parts[..1] }
484484
}
485485
FullDecoded::Infinite => {
486-
parts[0] = Part::Copy(if upper { b"INF" } else { b"inf" });
486+
parts[0] = Part::Copy(b"inf");
487487
Formatted { sign: sign, parts: &parts[..1] }
488488
}
489489
FullDecoded::Zero => {
@@ -557,11 +557,11 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
557557
let sign = determine_sign(sign, &full_decoded, negative);
558558
match full_decoded {
559559
FullDecoded::Nan => {
560-
parts[0] = Part::Copy(if upper { b"NAN" } else { b"nan" });
560+
parts[0] = Part::Copy(b"NaN");
561561
Formatted { sign: sign, parts: &parts[..1] }
562562
}
563563
FullDecoded::Infinite => {
564-
parts[0] = Part::Copy(if upper { b"INF" } else { b"inf" });
564+
parts[0] = Part::Copy(b"inf");
565565
Formatted { sign: sign, parts: &parts[..1] }
566566
}
567567
FullDecoded::Zero => {
@@ -589,10 +589,10 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
589589

590590
/// Formats given floating point number into the decimal form with exactly
591591
/// given number of fractional digits. The result is stored to the supplied parts
592-
/// array while utilizing given byte buffer as a scratch. `upper` is only used to
593-
/// determine the case of non-finite values, i.e. `inf` and `nan`. The first part
594-
/// to be rendered is always a `Part::Sign` (which can be an empty string
595-
/// if no sign is rendered).
592+
/// array while utilizing given byte buffer as a scratch. `upper` is currently
593+
/// unused but left for the future decision to change the case of non-finite values,
594+
/// i.e. `inf` and `nan`. The first part to be rendered is always a `Part::Sign`
595+
/// (which can be an empty string if no sign is rendered).
596596
///
597597
/// `format_exact` should be the underlying digit-generation function.
598598
/// You probably would want `strategy::grisu::format_exact` for this.
@@ -603,7 +603,7 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
603603
/// There should be at least 5 parts available, due to the worst case like
604604
/// `[+][0.][0000][45][0000]` with `frac_digits = 10`.
605605
pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
606-
sign: Sign, frac_digits: usize, upper: bool,
606+
sign: Sign, frac_digits: usize, _upper: bool,
607607
buf: &'a mut [u8], parts: &'a mut [Part<'a>]) -> Formatted<'a>
608608
where T: DecodableFloat, F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) {
609609
assert!(parts.len() >= 4);
@@ -612,11 +612,11 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
612612
let sign = determine_sign(sign, &full_decoded, negative);
613613
match full_decoded {
614614
FullDecoded::Nan => {
615-
parts[0] = Part::Copy(if upper { b"NAN" } else { b"nan" });
615+
parts[0] = Part::Copy(b"NaN");
616616
Formatted { sign: sign, parts: &parts[..1] }
617617
}
618618
FullDecoded::Infinite => {
619-
parts[0] = Part::Copy(if upper { b"INF" } else { b"inf" });
619+
parts[0] = Part::Copy(b"inf");
620620
Formatted { sign: sign, parts: &parts[..1] }
621621
}
622622
FullDecoded::Zero => {

src/libcoretest/num/flt2dec/mod.rs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -544,17 +544,17 @@ pub fn to_shortest_str_test<F>(mut f_: F)
544544
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 8, true), "-0.00000000");
545545

546546
assert_eq!(to_string(f, 1.0/0.0, Minus, 0, false), "inf");
547-
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 0, true), "INF");
547+
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 0, true), "inf");
548548
assert_eq!(to_string(f, 1.0/0.0, MinusPlus, 0, false), "+inf");
549-
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 0, true), "+INF");
550-
assert_eq!(to_string(f, 0.0/0.0, Minus, 0, false), "nan");
551-
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 1, true), "NAN");
552-
assert_eq!(to_string(f, 0.0/0.0, MinusPlus, 8, false), "nan");
553-
assert_eq!(to_string(f, 0.0/0.0, MinusPlusRaw, 64, true), "NAN");
549+
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 0, true), "+inf");
550+
assert_eq!(to_string(f, 0.0/0.0, Minus, 0, false), "NaN");
551+
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 1, true), "NaN");
552+
assert_eq!(to_string(f, 0.0/0.0, MinusPlus, 8, false), "NaN");
553+
assert_eq!(to_string(f, 0.0/0.0, MinusPlusRaw, 64, true), "NaN");
554554
assert_eq!(to_string(f, -1.0/0.0, Minus, 0, false), "-inf");
555-
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 1, true), "-INF");
555+
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 1, true), "-inf");
556556
assert_eq!(to_string(f, -1.0/0.0, MinusPlus, 8, false), "-inf");
557-
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-INF");
557+
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-inf");
558558

559559
assert_eq!(to_string(f, 3.14, Minus, 0, false), "3.14");
560560
assert_eq!(to_string(f, 3.14, MinusRaw, 0, false), "3.14");
@@ -638,17 +638,17 @@ pub fn to_shortest_exp_str_test<F>(mut f_: F)
638638
assert_eq!(to_string(f, -0.0, MinusPlusRaw, ( 5, 9), false), "-0e0");
639639

640640
assert_eq!(to_string(f, 1.0/0.0, Minus, (-4, 16), false), "inf");
641-
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, (-4, 16), true), "INF");
641+
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, (-4, 16), true), "inf");
642642
assert_eq!(to_string(f, 1.0/0.0, MinusPlus, (-4, 16), false), "+inf");
643-
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, (-4, 16), true), "+INF");
644-
assert_eq!(to_string(f, 0.0/0.0, Minus, ( 0, 0), false), "nan");
645-
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, ( 0, 0), true), "NAN");
646-
assert_eq!(to_string(f, 0.0/0.0, MinusPlus, (-9, -5), false), "nan");
647-
assert_eq!(to_string(f, 0.0/0.0, MinusPlusRaw, ( 5, 9), true), "NAN");
643+
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, (-4, 16), true), "+inf");
644+
assert_eq!(to_string(f, 0.0/0.0, Minus, ( 0, 0), false), "NaN");
645+
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, ( 0, 0), true), "NaN");
646+
assert_eq!(to_string(f, 0.0/0.0, MinusPlus, (-9, -5), false), "NaN");
647+
assert_eq!(to_string(f, 0.0/0.0, MinusPlusRaw, ( 5, 9), true), "NaN");
648648
assert_eq!(to_string(f, -1.0/0.0, Minus, ( 0, 0), false), "-inf");
649-
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, ( 0, 0), true), "-INF");
649+
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, ( 0, 0), true), "-inf");
650650
assert_eq!(to_string(f, -1.0/0.0, MinusPlus, (-9, -5), false), "-inf");
651-
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, ( 5, 9), true), "-INF");
651+
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, ( 5, 9), true), "-inf");
652652

653653
assert_eq!(to_string(f, 3.14, Minus, (-4, 16), false), "3.14");
654654
assert_eq!(to_string(f, 3.14, MinusRaw, (-4, 16), false), "3.14");
@@ -752,17 +752,17 @@ pub fn to_exact_exp_str_test<F>(mut f_: F)
752752
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 8, false), "-0.0000000e0");
753753

754754
assert_eq!(to_string(f, 1.0/0.0, Minus, 1, false), "inf");
755-
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 1, true), "INF");
755+
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 1, true), "inf");
756756
assert_eq!(to_string(f, 1.0/0.0, MinusPlus, 1, false), "+inf");
757-
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 1, true), "+INF");
758-
assert_eq!(to_string(f, 0.0/0.0, Minus, 8, false), "nan");
759-
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 8, true), "NAN");
760-
assert_eq!(to_string(f, 0.0/0.0, MinusPlus, 8, false), "nan");
761-
assert_eq!(to_string(f, 0.0/0.0, MinusPlusRaw, 8, true), "NAN");
757+
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 1, true), "+inf");
758+
assert_eq!(to_string(f, 0.0/0.0, Minus, 8, false), "NaN");
759+
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 8, true), "NaN");
760+
assert_eq!(to_string(f, 0.0/0.0, MinusPlus, 8, false), "NaN");
761+
assert_eq!(to_string(f, 0.0/0.0, MinusPlusRaw, 8, true), "NaN");
762762
assert_eq!(to_string(f, -1.0/0.0, Minus, 64, false), "-inf");
763-
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 64, true), "-INF");
763+
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 64, true), "-inf");
764764
assert_eq!(to_string(f, -1.0/0.0, MinusPlus, 64, false), "-inf");
765-
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-INF");
765+
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-inf");
766766

767767
assert_eq!(to_string(f, 3.14, Minus, 1, true), "3E0");
768768
assert_eq!(to_string(f, 3.14, MinusRaw, 1, false), "3e0");
@@ -973,17 +973,17 @@ pub fn to_exact_fixed_str_test<F>(mut f_: F)
973973
assert_eq!(to_string(f, -0.0, MinusPlusRaw, 8, true), "-0.00000000");
974974

975975
assert_eq!(to_string(f, 1.0/0.0, Minus, 0, false), "inf");
976-
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 1, true), "INF");
976+
assert_eq!(to_string(f, 1.0/0.0, MinusRaw, 1, true), "inf");
977977
assert_eq!(to_string(f, 1.0/0.0, MinusPlus, 8, false), "+inf");
978-
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 64, true), "+INF");
979-
assert_eq!(to_string(f, 0.0/0.0, Minus, 0, false), "nan");
980-
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 1, true), "NAN");
981-
assert_eq!(to_string(f, 0.0/0.0, MinusPlus, 8, false), "nan");
982-
assert_eq!(to_string(f, 0.0/0.0, MinusPlusRaw, 64, true), "NAN");
978+
assert_eq!(to_string(f, 1.0/0.0, MinusPlusRaw, 64, true), "+inf");
979+
assert_eq!(to_string(f, 0.0/0.0, Minus, 0, false), "NaN");
980+
assert_eq!(to_string(f, 0.0/0.0, MinusRaw, 1, true), "NaN");
981+
assert_eq!(to_string(f, 0.0/0.0, MinusPlus, 8, false), "NaN");
982+
assert_eq!(to_string(f, 0.0/0.0, MinusPlusRaw, 64, true), "NaN");
983983
assert_eq!(to_string(f, -1.0/0.0, Minus, 0, false), "-inf");
984-
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 1, true), "-INF");
984+
assert_eq!(to_string(f, -1.0/0.0, MinusRaw, 1, true), "-inf");
985985
assert_eq!(to_string(f, -1.0/0.0, MinusPlus, 8, false), "-inf");
986-
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-INF");
986+
assert_eq!(to_string(f, -1.0/0.0, MinusPlusRaw, 64, true), "-inf");
987987

988988
assert_eq!(to_string(f, 3.14, Minus, 0, false), "3");
989989
assert_eq!(to_string(f, 3.14, MinusRaw, 0, false), "3");

0 commit comments

Comments
 (0)