Skip to content

Commit c6d5a93

Browse files
committed
binding: update floating-point comparisons in tests
version 1.60 of the rust stdlib included a change to improve the accuracy of calculations in `Duration::try_from_secs_f32/64` (see [1]), which had a minor breaking change of slightly altering the calculated results. version 1.63 further tweaked this (see [2]). this commit updates tests to match the new calculated values from 1.63+, and thus fixes failure running tests in newer stable rust releases and helps us to fix CI failure. this is done at the expense of breaking the ability to run the tests with older rust versions, which seems reasonably acceptable at this time. for the record, the new values used here are those calculated using version 1.66. it has been suggested that rather than compare float values directly, it may be better for this crate to compare via the `float_eq` crate instead. this would essentially mean switching to a less accurate comparison. since some time has passed now since i originally encountered this problem, i think that just updating the values compared against is the best move at this time, though i am not necessarily against moving to use of `float_eq` at some point in future if this causes significant problems for users of older rust versions, or if we encounter further such issues from rust stdlib changes. note that in the original issue (see [3]) there were four functions whose doc-tests were failing, yet only three have needed to be modified here. the lack of needing to fix the fourth function's tests is presumably as a result of the changes made in rust v1.63. (the original issue was noticed with a v1.60 nightly). [1]: rust-lang/rust#90247 [2]: rust-lang/rust#96051 [3]: #48
1 parent 2f5ae7c commit c6d5a93

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

pulse-binding/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# [unreleased]
2+
3+
* Tweaked some doc-tests to work with rust v1.63+ (at the expense of not working with older
4+
versions). This relates to float-point calculation changes in `Duration::try_from_secs_f32/64`
5+
made in rust stdlib version 1.60 and further tweaked in 1.63. See [this issue][issue48].
6+
17
# 2.26.0 (January 13th, 2022)
28

39
* Changed the type of the `timestamp` member of `def::TimingInfo` from `Timeval` to `UnixTs` since
@@ -660,3 +666,4 @@ Note, version number 1.0.4 skipped (it was used for non-crate project changes).
660666
[`bitflags`]: https://docs.rs/bitflags
661667
[issue11]: https://github.com/jnqnfe/pulse-binding-rust/issues/11
662668
[issue26]: https://github.com/jnqnfe/pulse-binding-rust/issues/26
669+
[issue48]: https://github.com/jnqnfe/pulse-binding-rust/issues/48

pulse-binding/src/time/microseconds.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl MicroSeconds {
257257
/// ```rust
258258
/// # use libpulse_binding::time::MicroSeconds;
259259
/// assert_eq!(MicroSeconds::from_secs_f32(0.5), MicroSeconds(500_000));
260-
/// assert_eq!(MicroSeconds::from_secs_f32(2.3), MicroSeconds(2_300_000));
260+
/// assert_eq!(MicroSeconds::from_secs_f32(2.3), MicroSeconds(2_299_999));
261261
/// ```
262262
///
263263
/// These should panic.
@@ -510,8 +510,8 @@ impl MicroSeconds {
510510
/// let micros = MicroSeconds(2_700_000_000);
511511
///
512512
/// // Note the rounding errors that are clear here.
513-
/// assert_eq!(micros.mul_f32(3.14), MicroSeconds(8_478_000_152));
514-
/// assert_eq!(micros.mul_f32(3.14e5), MicroSeconds(847_800_018_512_379));
513+
/// assert_eq!(micros.mul_f32(3.14), MicroSeconds(8_478_000_000));
514+
/// assert_eq!(micros.mul_f32(3.14e5), MicroSeconds(847_800_000_000_000));
515515
/// ```
516516
///
517517
/// These should panic.
@@ -596,7 +596,7 @@ impl MicroSeconds {
596596
/// # use libpulse_binding::time::{MicroSeconds, MICROS_PER_SEC};
597597
/// let micros = MicroSeconds(2_700_000_000);
598598
///
599-
/// assert_eq!(micros.div_f32(3.14), MicroSeconds(859_872_559));
599+
/// assert_eq!(micros.div_f32(3.14), MicroSeconds(859_872_558));
600600
/// assert_eq!(micros.div_f32(3.14e5), MicroSeconds(8_598));
601601
/// ```
602602
///

0 commit comments

Comments
 (0)