1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

uucore:format:fix floating-point rounding

This change resolves issues with exponent calculation and usage,
ensuring more accurate formatting:

- Exponent for negative values can differ from 0
- Switching to decimal mode now follows the P > X ≥ −4 rule
This commit is contained in:
Alexander Shirokov 2024-12-30 22:33:40 +01:00
parent a3b7a08238
commit 4c330d43ba
No known key found for this signature in database
GPG key ID: 6020E4D7AFA8ECE7
2 changed files with 81 additions and 2 deletions

View file

@ -916,3 +916,50 @@ fn float_flag_position_space_padding() {
.succeeds()
.stdout_only(" +1.0");
}
#[test]
fn float_abs_value_less_than_one() {
new_ucmd!()
.args(&["%g", "0.1171875"])
.succeeds()
.stdout_only("0.117188");
// The original value from #7031 issue
new_ucmd!()
.args(&["%g", "-0.1171875"])
.succeeds()
.stdout_only("-0.117188");
new_ucmd!()
.args(&["%g", "0.01171875"])
.succeeds()
.stdout_only("0.0117188");
new_ucmd!()
.args(&["%g", "-0.01171875"])
.succeeds()
.stdout_only("-0.0117188");
new_ucmd!()
.args(&["%g", "0.001171875001"])
.succeeds()
.stdout_only("0.00117188");
new_ucmd!()
.args(&["%g", "-0.001171875001"])
.succeeds()
.stdout_only("-0.00117188");
}
#[test]
fn float_switch_switch_decimal_scientific() {
new_ucmd!()
.args(&["%g", "0.0001"])
.succeeds()
.stdout_only("0.0001");
new_ucmd!()
.args(&["%g", "0.00001"])
.succeeds()
.stdout_only("1e-05");
}