mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
uucore: format: force NaN back to lowercase
Fixes formatting of `NaN` to `nan`. Fixes part 1 of #7412.
This commit is contained in:
parent
c0a1179e7c
commit
e3872e8e8f
1 changed files with 15 additions and 2 deletions
|
@ -324,8 +324,9 @@ fn get_sign_indicator<T: PartialOrd + Default>(sign: PositiveSign, x: &T) -> Str
|
||||||
fn format_float_non_finite(f: f64, case: Case) -> String {
|
fn format_float_non_finite(f: f64, case: Case) -> String {
|
||||||
debug_assert!(!f.is_finite());
|
debug_assert!(!f.is_finite());
|
||||||
let mut s = format!("{f}");
|
let mut s = format!("{f}");
|
||||||
if case == Case::Uppercase {
|
match case {
|
||||||
s.make_ascii_uppercase();
|
Case::Lowercase => s.make_ascii_lowercase(), // Forces NaN back to nan.
|
||||||
|
Case::Uppercase => s.make_ascii_uppercase(),
|
||||||
}
|
}
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
@ -550,6 +551,18 @@ mod test {
|
||||||
assert_eq!(f(8), "010");
|
assert_eq!(f(8), "010");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn non_finite_float() {
|
||||||
|
use super::format_float_non_finite;
|
||||||
|
let f = |x| format_float_non_finite(x, Case::Lowercase);
|
||||||
|
assert_eq!(f(f64::NAN), "nan");
|
||||||
|
assert_eq!(f(f64::INFINITY), "inf");
|
||||||
|
|
||||||
|
let f = |x| format_float_non_finite(x, Case::Uppercase);
|
||||||
|
assert_eq!(f(f64::NAN), "NAN");
|
||||||
|
assert_eq!(f(f64::INFINITY), "INF");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decimal_float() {
|
fn decimal_float() {
|
||||||
use super::format_float_decimal;
|
use super::format_float_decimal;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue