You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking Issue for Duration::try_from_secs_{f32, f64} #83400
changed the title [-]Tracking Issue for `Duration::checked_from_secs_{f32, f64}`[/-][+]Tracking Issue for `Duration::try_from_secs_{f32, f64}`[/+]on Mar 23, 2021
This needs more testing to vet its behavior in the face of various interesting floating point values.
In particular, subnormal values and values close to the limit of f32 and f64's upper range.
This needs more testing to vet its behavior in the face of various interesting floating point values.
In particular, subnormal values and values close to the limit of f32 and f64's upper range.
This just currently checks what the othee panicking methods for the same thing do.
It is still unclear whether a different name would be better.
Once that is resolved, we'll need a stabilisation PR and then, once that gets approved, it will be a month or two until it appears in stable
EDIT: Note: #96051 changes the rounding mode to round-to-nearest instead of truncate. (note on the note: That pr is also changing the stabilised methods from_secs_*, but it would be nice to have it correct when it is first stabilised)
Because it isn't clear from TryFrom that it is meant to be seconds. It could be milliseconds or hours or days or some other reasonable measurement.
This is the same reason why Duration doesn't impl From<u128> or something. It could likewise be a lot of other units.
I will prepare a stabilization PR shortly and hope we can resolve the open question on error type naming in the context of an FCP. I hope that's an ok way to approach this.
Activity
[-]Tracking Issue for `Duration::checked_from_secs_{f32, f64}`[/-][+]Tracking Issue for `Duration::try_from_secs_{f32, f64}`[/+]workingjubilee commentedon Apr 10, 2021
This needs more testing to vet its behavior in the face of various interesting floating point values.
In particular, subnormal values and values close to the limit of f32 and f64's upper range.
mbartlett21 commentedon Apr 15, 2021
This just currently checks what the othee panicking methods for the same thing do.
Rollup merge of rust-lang#82179 - mbartlett21:patch-5, r=joshtriplett
newpavlov commentedon Oct 27, 2021
The new code in #90247 should handle all interesting values perfectly.
nvzqz commentedon May 13, 2022
What is left to stabilize this? It is important to me that time conversions I'm using don't panic.
mbartlett21 commentedon May 16, 2022
There is still an unresolved question:
What should the error type be called?
In the original PR, I called it
FromSecsError.In Improve Duration::try_from_secs_f32/64 accuracy by directly processing exponent and mantissa #90247, @newpavlov updated the error type to
FromFloatSecsError.It is still unclear whether a different name would be better.
Once that is resolved, we'll need a stabilisation PR and then, once that gets approved, it will be a month or two until it appears in stable
EDIT: Note: #96051 changes the rounding mode to round-to-nearest instead of truncate. (note on the note: That pr is also changing the stabilised methods from_secs_*, but it would be nice to have it correct when it is first stabilised)
arniu commentedon Aug 15, 2022
Why not just
impl TryFrom<f32 | f64> for Duration?mbartlett21 commentedon Aug 15, 2022
Because it isn't clear from
TryFromthat it is meant to be seconds. It could be milliseconds or hours or days or some other reasonable measurement.This is the same reason why
Durationdoesn't implFrom<u128>or something. It could likewise be a lot of other units.lopopolo commentedon Sep 25, 2022
I came across this unstable API when debugging a panic in a time crate I maintain:
Time::checked_add_f64andTime::checked_sub_f64panic on too large input artichoke/artichoke#2194I will prepare a stabilization PR shortly and hope we can resolve the open question on error type naming in the context of an FCP. I hope that's an ok way to approach this.
lopopolo commentedon Sep 25, 2022
I have pushed a stabilization PR and stabilization report here: #102271.
The stabilization PR renames the error type to
TryFromFloatSecsto indicate the fallibility of the method likeVec::try_reserveandTryReserveError.Rollup merge of rust-lang#103059 - beetrees:duration-from-negative-ze…
Rollup merge of rust-lang#102271 - lopopolo:lopopolo/stabilize-durati…
Rollup merge of rust-lang#102271 - lopopolo:lopopolo/stabilize-durati…
Fix ffprobe duration conversion panics
Stabilize `duration_checked_float`
Rollup merge of #102271 - lopopolo:lopopolo/stabilize-duration-try-fr…
Dylan-DPC commentedon Feb 29, 2024
This is stabilised already in #102271
Rollup merge of rust-lang#82179 - mbartlett21:patch-5, r=joshtriplett