Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration div mul extras #52813

Merged
merged 18 commits into from Sep 21, 2018
Merged

Duration div mul extras #52813

merged 18 commits into from Sep 21, 2018

Conversation

@newpavlov
Copy link
Contributor

newpavlov commented Jul 28, 2018

Successor of #52556.

This PR adds the following impls:

  • impl Mul<Duration> for u32 (to allow 10*SECOND in addition to SECOND*10)
  • impl Mul<f64> for Duration (to allow 2.5*SECOND vs 2*SECOND + 500*MILLISECOND)
  • impl Mul<Duration> for f64
  • impl MulAssign<f64> for Duration
  • impl Div<f64> for Duration
  • impl DivAssign<f64> for Duration
  • impl Div<Duration> for Duration (Output = f64, can be useful e.g. for duration/MINUTE)

f64 is chosen over f32 to minimize rounding errors. (52 bits fraction precision vs Duration's ~94 bit)

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jul 28, 2018

r? @withoutboats

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Jul 28, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:03:54]    Compiling rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:03:56] error[E0308]: mismatched types
[00:03:56]    --> libcore/time.rs:535:20
[00:03:56]     |
[00:03:56] 535 |             nanos: nanos as u64,
[00:03:56]     |                    ^^^^^^^^^^^^ expected u32, found u64
[00:03:56] error[E0308]: mismatched types
[00:03:56]    --> libcore/time.rs:561:20
[00:03:56]     |
[00:03:56]     |
[00:03:56] 561 |             nanos: nanos as u64,
[00:03:56]     |                    ^^^^^^^^^^^^ expected u32, found u64
[00:03:56] error[E0308]: mismatched types
[00:03:56]    --> libcore/time.rs:610:20
[00:03:56]     |
[00:03:56]     |
[00:03:56] 610 |             nanos: nanos as u64,
[00:03:56]     |                    ^^^^^^^^^^^^ expected u32, found u64
[00:03:56] error: aborting due to 3 previous errors
[00:03:56] 
[00:03:56] For more information about this error, try `rustc --explain E0308`.
[00:03:56] error: Could not compile `core`.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Jul 28, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:04:15]    Compiling cc v1.0.18
[00:04:15]    Compiling core v0.0.0 (file:///checkout/src/libcore)
[00:04:15]    Compiling build_helper v0.1.0 (file:///checkout/src/build_helper)
[00:04:15]    Compiling unwind v0.0.0 (file:///checkout/src/libunwind)
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 521 |         if !nanos.is_finite() {
[00:04:18]     |             ^^^^^ help: try: `self.nanos`
[00:04:18] 
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 524 |         if nanos > (u128::MAX as f64) {
[00:04:18]     |            ^^^^^ help: try: `self.nanos`
[00:04:18] 
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 527 |         let nanos_u128 = nanos.round() as u128;
[00:04:18]     |                          ^^^^^ help: try: `self.nanos`
[00:04:18] 
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 547 |         if !nanos.is_finite() {
[00:04:18] 
[00:04:18] 
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 550 |         if nanos > (u128::MAX as f64) {
[00:04:18] 
[00:04:18] 
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 553 |         let nanos_u128 = nanos.round() as u128;
[00:04:18] 
[00:04:18] 
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 596 |         if !nanos.is_finite() {
[00:04:18]     |             ^^^^^ help: try: `self.nanos`
[00:04:18] 
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 599 |         if nanos > (u128::MAX as f64) {
[00:04:18]     |            ^^^^^ help: try: `self.nanos`
[00:04:18] 
[00:04:18] error[E0425]: cannot find value `nanos` in this scope
[00:04:18]     |
[00:04:18]     |
[00:04:18] 602 |         let nanos_u128 = nanos.round() as u128;
[00:04:18]     |                          ^^^^^ help: try: `self.nanos`
[00:04:22]    Compiling compiler_builtins v0.0.0 (file:///checkout/src/rustc/compiler_builtins_shim)
[00:04:22]    Compiling cmake v0.1.31
[00:04:22]    Compiling alloc_jemalloc v0.0.0 (file:///checkout/src/liballoc_jemalloc)
[00:04:26]    Compiling std v0.0.0 (file:///checkout/src/libstd)

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Jul 28, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:04:06]    Compiling rustc_tsan v0.0.0 (file:///checkout/src/librustc_tsan)
[00:04:07]    Compiling rustc_lsan v0.0.0 (file:///checkout/src/librustc_lsan)
[00:04:08]    Compiling rustc_asan v0.0.0 (file:///checkout/src/librustc_asan)
[00:04:09]    Compiling rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:04:11] error[E0599]: no method named `round` found for type `f64` in the current scope
[00:04:11]     |
[00:04:11]     |
[00:04:11] 527 |         let nanos_u128 = nanos_f64.round() as u128;
[00:04:11] 
[00:04:11] 
[00:04:11] error[E0599]: no method named `round` found for type `f64` in the current scope
[00:04:11]     |
[00:04:11]     |
[00:04:11] 553 |         let nanos_u128 = nanos_f64.round() as u128;
[00:04:11] 
[00:04:11] 
[00:04:11] error[E0599]: no method named `round` found for type `f64` in the current scope
[00:04:11]     |
[00:04:11]     |
[00:04:11] 602 |         let nanos_u128 = nanos_f64.round() as u128;
[00:04:11] 
[00:04:11] error: aborting due to 3 previous errors
[00:04:11] 
[00:04:11] For more information about this error, try `rustc --explain E0599`.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Jul 29, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:03:55]    Compiling build_helper v0.1.0 (file:///checkout/src/build_helper)
[00:04:01]    Compiling compiler_builtins v0.0.0 (file:///checkout/src/rustc/compiler_builtins_shim)
[00:04:01]    Compiling cmake v0.1.31
[00:04:01]    Compiling alloc_jemalloc v0.0.0 (file:///checkout/src/liballoc_jemalloc)
[00:04:05] error[E0053]: method `div` has an incompatible type for trait
[00:04:05]     |
[00:04:05]     |
[00:04:05] 619 |     fn div(self, rhs: Duration) -> Duration {
[00:04:05]     |                                    ^^^^^^^^ expected f64, found struct `time::Duration`
[00:04:05]    ::: libcore/ops/arith.rs:441:31
[00:04:05]     |
[00:04:05]     |
[00:04:05] 441 |     fn div(self, rhs: RHS) -> Self::Output;
[00:04:05]     |                               ------------ type in trait
[00:04:05]     |
[00:04:05]     = note: expected type `fn(time::Duration, time::Duration) -> f64`
[00:04:05]                found type `fn(time::Duration, time::Duration) -> time::Duration`
[00:04:05]    Compiling std v0.0.0 (file:///checkout/src/libstd)
[00:04:06] error: aborting due to previous error
[00:04:06] 
[00:04:06] For more information about this error, try `rustc --explain E0053`.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Jul 29, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:04:01]    Compiling rustc_tsan v0.0.0 (file:///checkout/src/librustc_tsan)
[00:04:02]    Compiling rustc_asan v0.0.0 (file:///checkout/src/librustc_asan)
[00:04:03]    Compiling rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:04:04]    Compiling rustc_lsan v0.0.0 (file:///checkout/src/librustc_lsan)
[00:04:05] error[E0277]: cannot divide `f64` by `time::Duration`
[00:04:05]     |
[00:04:05]     |
[00:04:05] 621 |         let nanos1 = (NPS * (self.secs as f64) + (self.nanos as f64)) / rhs;
[00:04:05]     |                                                                       ^ no implementation for `f64 / time::Duration`
[00:04:05]     |
[00:04:05]     = help: the trait `ops::arith::Div<time::Duration>` is not implemented for `f64`
[00:04:05] 
[00:04:05] error[E0277]: cannot divide `f64` by `time::Duration`
[00:04:05]     |
[00:04:05]     |
[00:04:05] 622 |         let nanos2 = (NPS * (self.secs as f64) + (self.nanos as f64)) / rhs;
[00:04:05]     |                                                                       ^ no implementation for `f64 / time::Duration`
[00:04:05]     |
[00:04:05]     = help: the trait `ops::arith::Div<time::Duration>` is not implemented for `f64`
[00:04:05] error: aborting due to 2 previous errors
[00:04:05] 
[00:04:05] For more information about this error, try `rustc --explain E0277`.
[00:04:05] error: Could not compile `core`.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Jul 29, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:03:51]    Compiling unwind v0.0.0 (file:///checkout/src/libunwind)
[00:03:55] warning: unnecessary parentheses around assigned value
[00:03:55]    --> libcore/time.rs:621:22
[00:03:55]     |
[00:03:55] 621 |         let nanos1 = (NPS * (self.secs as f64) + (self.nanos as f64));
[00:03:55]     |
[00:03:55]     = note: #[warn(unused_parens)] on by default
[00:03:55] 
[00:03:55] warning: unnecessary parentheses around assigned value
[00:03:55] warning: unnecessary parentheses around assigned value
[00:03:55]    --> libcore/time.rs:622:22
[00:03:55]     |
[00:03:55] 622 |         let nanos2 = (NPS * (rhs.secs as f64) + (rhs.nanos as f64));
[00:03:55] 
[00:03:57]    Compiling compiler_builtins v0.0.0 (file:///checkout/src/rustc/compiler_builtins_shim)
[00:03:57]    Compiling cmake v0.1.31
[00:03:57]    Compiling alloc_jemalloc v0.0.0 (file:///checkout/src/liballoc_jemalloc)
---
[00:18:35]    Compiling alloc_jemalloc v0.0.0 (file:///checkout/src/liballoc_jemalloc)
[00:18:36] error: unnecessary parentheses around assigned value
[00:18:36]    --> libcore/time.rs:621:22
[00:18:36]     |
[00:18:36] 621 |         let nanos1 = (NPS * (self.secs as f64) + (self.nanos as f64));
[00:18:36]     |
[00:18:36]     = note: `-D unused-parens` implied by `-D warnings`
[00:18:36] 
[00:18:36] error: unnecessary parentheses around assigned value
[00:18:36] error: unnecessary parentheses around assigned value
[00:18:36]    --> libcore/time.rs:622:22
[00:18:36]     |
[00:18:36] 622 |         let nanos2 = (NPS * (rhs.secs as f64) + (rhs.nanos as f64));
[00:18:36] 
[00:18:38]    Compiling std v0.0.0 (file:///checkout/src/libstd)
[00:18:38]    Compiling rustc_asan v0.0.0 (file:///checkout/src/librustc_asan)
[00:18:38]    Compiling rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
---
[00:18:52] Caused by:
[00:18:52]   process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name core libcore/lib.rs --color always --error-format json --crate-type lib --emit=dep-info,link -C opt-level=2 -C metadata=1cbcabaa1ea822b5 -C extra-filename=-1cbcabaa1ea822b5 --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps` (exit code: 1)
[00:18:52] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:18:52] expected success, got: exit code: 101
[00:18:52] thread 'main' panicked at 'cargo must succeed', bootstrap/compile.rs:1119:9
[00:18:52] travis_fold:end:stage1-std

[00:18:52] travis_time:end:stage1-std:start=1532826884464708842,finish=1532826907795491003,duration=23330782161


[00:18:52] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:18:52] Build completed unsuccessfully in 0:15:02
[00:18:52] Makefile:28: recipe for target 'all' failed
[00:18:52] make: *** [all] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:1246c863
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:09fea60c:start=1532826908394679009,finish=1532826908402812828,duration=8133819
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:012d5ebc
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:025e0a61
travis_time:start:025e0a61
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0718980c
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Jul 29, 2018

Could you squash all fixups into a single commit?

@newpavlov newpavlov force-pushed the newpavlov:duration_mul_div_extras branch from 9b0d0b5 to c24fb12 Jul 29, 2018
@newpavlov

This comment has been minimized.

Copy link
Contributor Author

newpavlov commented Jul 29, 2018

Done.

if !nanos_f64.is_finite() {
panic!("got non-finite value when multiplying duration by float");
}
if nanos_f64 > (u128::MAX as f64) {

This comment has been minimized.

Copy link
@kennytm

kennytm Jul 29, 2018

Member

The upper limit is u64::MAX * NANOS_PER_SEC (1.8 × 1028) which is a much smaller number than u128::MAX (3.4 × 1038). If you check for the former you don't need the second secs > (u64::MAX as u128) below.

This comment has been minimized.

Copy link
@newpavlov

newpavlov Jul 29, 2018

Author Contributor

I was conservative about potential edge effects. So you think it will be enough to just check the following condition?

nanos_f64 > ((u64::MAX as u128)*(NANOS_PER_SEC as u128)) as f64

This comment has been minimized.

Copy link
@kennytm

kennytm Jul 29, 2018

Member

@newpavlov Yes. But make this a const please.


fn mul(self, rhs: f64) -> Duration {
const NPS: f64 = NANOS_PER_SEC as f64;
let nanos_f64 = rhs * (NPS * (self.secs as f64) + (self.nanos as f64));

This comment has been minimized.

Copy link
@kennytm

kennytm Jul 29, 2018

Member

Consider panicking when !(rhs >= 0).

This comment has been minimized.

Copy link
@newpavlov

newpavlov Jul 29, 2018

Author Contributor

Good point.

@newpavlov newpavlov force-pushed the newpavlov:duration_mul_div_extras branch from c2eb698 to 9246687 Jul 29, 2018
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jul 29, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:03:58]    Compiling rustc_lsan v0.0.0 (file:///checkout/src/librustc_lsan)
[00:03:59]    Compiling rustc_asan v0.0.0 (file:///checkout/src/librustc_asan)
[00:04:00]    Compiling rustc_msan v0.0.0 (file:///checkout/src/librustc_msan)
[00:04:01]    Compiling rustc_tsan v0.0.0 (file:///checkout/src/librustc_tsan)
[00:04:02] error[E0599]: no method named `is_sign_negative` found for type `time::Duration` in the current scope
[00:04:02]     |
[00:04:02]     |
[00:04:02] 65  | pub struct Duration {
[00:04:02]     | ------------------- method `is_sign_negative` not found for this
[00:04:02] ...
[00:04:02] 544 |         if rhs.is_sign_negative() {
[00:04:02] 
[00:04:03] error: aborting due to previous error
[00:04:03] 
[00:04:03] For more information about this error, try `rustc --explain E0599`.
---
156608 ./.git/modules/src
149124 ./src/llvm-emscripten/test
145504 ./obj/build/bootstrap/debug/incremental
130636 ./obj/build/bootstrap/debug/incremental/bootstrap-c7ee2tfsizs
130632 ./obj/build/bootstrap/debug/incremental/bootstrap-c7ee2tfsizs/s-f3cg5qdtg9-1vl24hh-11rkeiafedqcr
97532 ./obj/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends
77624 ./.git/modules/src/tools
71508 ./src/llvm/lib
70304 ./obj/build/x86_64-unknown-linux-gnu/native

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@newpavlov newpavlov force-pushed the newpavlov:duration_mul_div_extras branch from 9246687 to 9086139 Jul 29, 2018
@newpavlov newpavlov force-pushed the newpavlov:duration_mul_div_extras branch from 9086139 to 12d8f27 Jul 29, 2018
fn mul(self, rhs: Duration) -> Duration {
const NPS: f64 = NANOS_PER_SEC as f64;
if self.is_sign_negative() {
panic!("duration can not be multiplied by negative float");

This comment has been minimized.

Copy link
@scottmcm

scottmcm Jul 30, 2018

Member

This will trigger for a NaN with the sign bit set, which feels like it'd be better reported under non-finite, so maybe just use self < 0 here? Also, multiplying a duration by negative zero seems like it should successfully give a zero duration, not a panic.

type Output = Duration;

fn mul(self, rhs: Duration) -> Duration {
rhs.checked_mul(self).expect("overflow when multiplying scalar by duration")

This comment has been minimized.

Copy link
@scottmcm

scottmcm Jul 30, 2018

Member

Maybe just use rhs * self to avoid repeating things?

This comment has been minimized.

Copy link
@newpavlov

newpavlov Jul 30, 2018

Author Contributor

They have different panic messages "multiplying scalar by duration" vs "multiplying duration by scalar"

This comment has been minimized.

Copy link
@newpavlov

newpavlov Jul 30, 2018

Author Contributor

If having different panic messages is not important, then I'll change it and f64 impl to rhs * self.

@newpavlov newpavlov force-pushed the newpavlov:duration_mul_div_extras branch from 5cc5272 to 2ddc2ea Jul 30, 2018
@newpavlov newpavlov force-pushed the newpavlov:duration_mul_div_extras branch from 2ddc2ea to 2c300fa Jul 30, 2018
@newpavlov

This comment has been minimized.

Copy link
Contributor Author

newpavlov commented Aug 2, 2018

Considering Rust 1.28 release should I change stabilization version to 1.30.0?

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Aug 3, 2018

@newpavlov Yes.

@@ -30,6 +30,7 @@ const NANOS_PER_MILLI: u32 = 1_000_000;
const NANOS_PER_MICRO: u32 = 1_000;
const MILLIS_PER_SEC: u64 = 1_000;
const MICROS_PER_SEC: u64 = 1_000_000;
const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128) - 1) as f64;

This comment has been minimized.

Copy link
@ollie27

ollie27 Sep 13, 2018

Contributor

The - 1 here doesn't change the value because f64 doesn't have enough precision so this constant ends up being exactly 1ns greater than the largest possible Duration. Either this constant needs to be changed to the next smallest f64 or the check below needs to be changed to nanos >= MAX_NANOS_F64. from_float_secs(2f64.powi(64)) should trigger an overflow but currently it returns a Duration of 0ns.

This comment has been minimized.

Copy link
@newpavlov

newpavlov Sep 19, 2018

Author Contributor

Ah, yes, it should've been >=. Fixed.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Sep 13, 2018

@bors: r+

Looks good to me, thanks!

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Sep 13, 2018

📌 Commit 2aca697 has been approved by alexcrichton

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Sep 13, 2018

@bors: r-

er actually, mind filing a tracking issue and filling that in?

@newpavlov

This comment has been minimized.

Copy link
Contributor Author

newpavlov commented Sep 19, 2018

Done.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Sep 19, 2018

@bors: r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Sep 19, 2018

📌 Commit fd7565b has been approved by alexcrichton

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Sep 19, 2018

⌛️ Testing commit fd7565b with merge 3c8c357...

bors added a commit that referenced this pull request Sep 19, 2018
Duration div mul extras

Successor of #52556.

This PR adds the following `impl`s:
- `impl Mul<Duration> for u32` (to allow `10*SECOND` in addition to `SECOND*10`)
- `impl Mul<f64> for Duration` (to allow `2.5*SECOND` vs `2*SECOND + 500*MILLISECOND`)
- `impl Mul<Duration> for f64`
- `impl MulAssign<f64> for Duration`
- `impl Div<f64> for Duration`
- `impl DivAssign<f64> for Duration`
- `impl Div<Duration> for Duration` (`Output = f64`, can be useful e.g. for `duration/MINUTE`)

`f64` is chosen over `f32` to minimize rounding errors. (52 bits fraction precision vs `Duration`'s ~94 bit)
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Sep 19, 2018

💔 Test failed - status-appveyor

@kennytm

This comment has been minimized.

Copy link
Member

kennytm commented Sep 20, 2018

@bors retry 3 hour timeout

kennytm added a commit to kennytm/rust that referenced this pull request Sep 20, 2018
…r=alexcrichton

Duration div mul extras

Successor of rust-lang#52556.

This PR adds the following `impl`s:
- `impl Mul<Duration> for u32` (to allow `10*SECOND` in addition to `SECOND*10`)
- `impl Mul<f64> for Duration` (to allow `2.5*SECOND` vs `2*SECOND + 500*MILLISECOND`)
- `impl Mul<Duration> for f64`
- `impl MulAssign<f64> for Duration`
- `impl Div<f64> for Duration`
- `impl DivAssign<f64> for Duration`
- `impl Div<Duration> for Duration` (`Output = f64`, can be useful e.g. for `duration/MINUTE`)

`f64` is chosen over `f32` to minimize rounding errors. (52 bits fraction precision vs `Duration`'s ~94 bit)
bors added a commit that referenced this pull request Sep 20, 2018
Rollup of 16 pull requests

Successful merges:

 - #52813 (Duration div mul extras)
 - #53470 (Warn about metadata loader errors)
 - #54233 (Remove LLVM 3.9 workaround.)
 - #54257 (Switch wasm math symbols to their original names)
 - #54258 (Enable fatal warnings for the wasm32 linker)
 - #54266 (Update LLVM to fix "bool" arguments on PPC32)
 - #54290 (Switch linker for aarch64-pc-windows-msvc from LLD to MSVC)
 - #54292 (Suggest array indexing when tuple indexing on an array)
 - #54295 (A few cleanups and minor improvements to rustc/traits)
 - #54298 (miri: correctly compute expected alignment for field)
 - #54317 (Implement the dbg!(..) macro)
 - #54333 (Update The Book to latest)
 - #54337 (Remove unneeded clone() from tests in librustdoc)
 - #54346 (rustc: future-proof error reporting for polymorphic constants in types.)
 - #54362 (Pass --batch to gdb)
 - #54367 (Add regression test for thread local static mut borrows)

Failed merges:

r? @ghost
bors added a commit that referenced this pull request Sep 20, 2018
Rollup of 15 pull requests

Successful merges:

 - #52813 (Duration div mul extras)
 - #53470 (Warn about metadata loader errors)
 - #54233 (Remove LLVM 3.9 workaround.)
 - #54257 (Switch wasm math symbols to their original names)
 - #54258 (Enable fatal warnings for the wasm32 linker)
 - #54266 (Update LLVM to fix "bool" arguments on PPC32)
 - #54290 (Switch linker for aarch64-pc-windows-msvc from LLD to MSVC)
 - #54292 (Suggest array indexing when tuple indexing on an array)
 - #54295 (A few cleanups and minor improvements to rustc/traits)
 - #54298 (miri: correctly compute expected alignment for field)
 - #54333 (Update The Book to latest)
 - #54337 (Remove unneeded clone() from tests in librustdoc)
 - #54346 (rustc: future-proof error reporting for polymorphic constants in types.)
 - #54362 (Pass --batch to gdb)
 - #54367 (Add regression test for thread local static mut borrows)
@bors bors merged commit fd7565b into rust-lang:master Sep 21, 2018
1 of 2 checks passed
1 of 2 checks passed
homu Test failed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Centril Centril added this to the 1.31 milestone Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.