mirror of
https://github.com/imsnif/bandwhich.git
synced 2026-02-09 01:59:18 +08:00
Fix Windows FP discrepancy issue in test (#400)
* Fix Windows FP discrepancy issue in test * Write changelog
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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")]
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user