Fix Windows FP discrepancy issue in test (#400)

* Fix Windows FP discrepancy issue in test

* Write changelog
This commit is contained in:
cyqsimon
2024-04-15 16:32:44 +08:00
committed by GitHub
parent 86a17cb002
commit 2ac352d490
3 changed files with 761 additions and 751 deletions

View File

@@ -13,7 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* Remove unnecessary logging synchronisation #381 - @cyqsimon
* Apply suggestions from new clippy lint clippy::assigning_clones #382 - @cyqsimon
* Fix IPv6 socket detect logic #383 - @cyqsimon
* Support build for `target_os`` `android` #384 - @flxo
* Support build for `target_os` `android` #384 - @flxo
* Fix Windows FP discrepancy issue in test #400 - @cyqsimon
## Added

View File

@@ -4,8 +4,10 @@ use derivative::Derivative;
use crate::cli::UnitFamily;
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Derivative)]
#[derivative(Debug)]
pub struct DisplayBandwidth {
#[derivative(Debug(format_with = "fmt_f64"))]
pub bandwidth: f64,
pub unit_family: BandwidthUnitFamily,
}
@@ -17,6 +19,14 @@ impl fmt::Display for DisplayBandwidth {
}
}
/// Custom formatter with reduced precision.
///
/// Workaround for FP calculation discrepancy between Unix and Windows.
/// See https://github.com/rust-lang/rust/issues/111405#issuecomment-2055964223.
fn fmt_f64(val: &f64, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{val:.10e}")
}
/// Type wrapper around [`UnitFamily`] to provide extra functionality.
#[derive(Copy, Clone, Derivative, Default, Eq, PartialEq)]
#[derivative(Debug = "transparent")]