mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
numfmt: handle negative zero values
This commit is contained in:
parent
418518a443
commit
dedb6289dd
2 changed files with 10 additions and 1 deletions
|
@ -161,7 +161,11 @@ fn transform_from(s: &str, opts: &TransformOptions) -> Result<f64> {
|
||||||
remove_suffix(i, suffix, &opts.from).map(|n| {
|
remove_suffix(i, suffix, &opts.from).map(|n| {
|
||||||
// GNU numfmt doesn't round values if no --from argument is provided by the user
|
// GNU numfmt doesn't round values if no --from argument is provided by the user
|
||||||
if opts.from == Unit::None {
|
if opts.from == Unit::None {
|
||||||
|
if n == -0.0 {
|
||||||
|
0.0
|
||||||
|
} else {
|
||||||
n
|
n
|
||||||
|
}
|
||||||
} else if n < 0.0 {
|
} else if n < 0.0 {
|
||||||
-n.abs().ceil()
|
-n.abs().ceil()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -184,6 +184,11 @@ fn test_negative() {
|
||||||
.stdout_is("-1.0Ki\n-1.2Mi\n-103Mi\n");
|
.stdout_is("-1.0Ki\n-1.2Mi\n-103Mi\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_negative_zero() {
|
||||||
|
new_ucmd!().pipe_in("-0\n-0.0").run().stdout_is("0\n0.0\n");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_no_op() {
|
fn test_no_op() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue