-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for duration_float #54361
Comments
What needs to happen before this can be stabilized? |
The only sane options are "have versions for both", or " Also, yes, what needs to happen for this to stabilize? |
I guess we probably should rename methods to |
What can I do to help? |
|
…chton Consistent naming for duration_float methods and additional f32 methods `duration_float` tracking issue: rust-lang#54361 New list of methods: - `as_secs_f64(&self) -> f64` - `as_secs_f32(&self) -> f32` - `from_secs_f64(secs: f64) -> Duration` - `from_secs_f32(secs: f32) -> Duration` - `mul_f64(self, rhs: f64) -> Duration` - `mul_f32(self, rhs: f32) -> Duration` - `div_f64(self, rhs: f64) -> Duration` - `div_f32(self, rhs: f64) -> Duration` - `div_duration_f64(self, rhs: Duration) -> f64` - `div_duration_f32(self, rhs: Duration) -> f32` With [`num_traits::Float`](https://docs.rs/num-traits/0.2.6/num_traits/float/trait.Float.html) we could've reduced number of methods by factor of two, but unfortunately it's not part of `std`.
…chton Consistent naming for duration_float methods and additional f32 methods `duration_float` tracking issue: rust-lang#54361 New list of methods: - `as_secs_f64(&self) -> f64` - `as_secs_f32(&self) -> f32` - `from_secs_f64(secs: f64) -> Duration` - `from_secs_f32(secs: f32) -> Duration` - `mul_f64(self, rhs: f64) -> Duration` - `mul_f32(self, rhs: f32) -> Duration` - `div_f64(self, rhs: f64) -> Duration` - `div_f32(self, rhs: f64) -> Duration` - `div_duration_f64(self, rhs: Duration) -> f64` - `div_duration_f32(self, rhs: Duration) -> f32` With [`num_traits::Float`](https://docs.rs/num-traits/0.2.6/num_traits/float/trait.Float.html) we could've reduced number of methods by factor of two, but unfortunately it's not part of `std`.
…chton Consistent naming for duration_float methods and additional f32 methods `duration_float` tracking issue: rust-lang#54361 New list of methods: - `as_secs_f64(&self) -> f64` - `as_secs_f32(&self) -> f32` - `from_secs_f64(secs: f64) -> Duration` - `from_secs_f32(secs: f32) -> Duration` - `mul_f64(self, rhs: f64) -> Duration` - `mul_f32(self, rhs: f32) -> Duration` - `div_f64(self, rhs: f64) -> Duration` - `div_f32(self, rhs: f64) -> Duration` - `div_duration_f64(self, rhs: Duration) -> f64` - `div_duration_f32(self, rhs: Duration) -> f32` With [`num_traits::Float`](https://docs.rs/num-traits/0.2.6/num_traits/float/trait.Float.html) we could've reduced number of methods by factor of two, but unfortunately it's not part of `std`.
…chton Consistent naming for duration_float methods and additional f32 methods `duration_float` tracking issue: rust-lang#54361 New list of methods: - `as_secs_f64(&self) -> f64` - `as_secs_f32(&self) -> f32` - `from_secs_f64(secs: f64) -> Duration` - `from_secs_f32(secs: f32) -> Duration` - `mul_f64(self, rhs: f64) -> Duration` - `mul_f32(self, rhs: f32) -> Duration` - `div_f64(self, rhs: f64) -> Duration` - `div_f32(self, rhs: f64) -> Duration` - `div_duration_f64(self, rhs: Duration) -> f64` - `div_duration_f32(self, rhs: Duration) -> f32` With [`num_traits::Float`](https://docs.rs/num-traits/0.2.6/num_traits/float/trait.Float.html) we could've reduced number of methods by factor of two, but unfortunately it's not part of `std`.
…chton Consistent naming for duration_float methods and additional f32 methods `duration_float` tracking issue: rust-lang#54361 New list of methods: - `as_secs_f64(&self) -> f64` - `as_secs_f32(&self) -> f32` - `from_secs_f64(secs: f64) -> Duration` - `from_secs_f32(secs: f32) -> Duration` - `mul_f64(self, rhs: f64) -> Duration` - `mul_f32(self, rhs: f32) -> Duration` - `div_f64(self, rhs: f64) -> Duration` - `div_f32(self, rhs: f64) -> Duration` - `div_duration_f64(self, rhs: Duration) -> f64` - `div_duration_f32(self, rhs: Duration) -> f32` With [`num_traits::Float`](https://docs.rs/num-traits/0.2.6/num_traits/float/trait.Float.html) we could've reduced number of methods by factor of two, but unfortunately it's not part of `std`.
What's left to do to stabilize this feature? Any ETA? |
It looks like this is finished and can be marked as stabilized, and so incorporated into the next stable release. Is there anything I can do to help with that? |
…excrichton Stabilize duration_float Closes: rust-lang#54361
Is there any discussion or reasoning of why such duplicative interface was chosen? It seems that a generic interface like I've found only this mention:
But one can argue that in this situation another addhoc inner trait can be introduced in Would you be so kind to explain the reasoning of current stabilized interface? |
Yeah, having standard library traits for floats and ints implemented by all corresponding types would be good for many places. But this is probably not the place to discuss that in particular. I also feel this API is very duplicating. My interpretation is that the reasoning behind it is that there is some loss of precision involved with using floats, and people want that to stand out so it does not go unnoticed. See this message and the messages leading up to it: #62756 (comment) If there were a EDIT: Probably better to have a specified generic, so callers can explicitly state the resolution: EDIT2: This can be done with current standard library like |
@faern why not something like
Would you be so kind to point me to right places where this topic can be raised, discussed and won't remain unnoticed? |
rust-lang/rust#54361 stabilised :)
rust-lang/rust#54361 stabilised :)
rust-lang/rust#54361 stabilised :)
rust-lang/rust#54361 stabilised :)
rust-lang/rust#54361 stabilised :)
rust-lang/rust#54361 stabilised :)
For future-comers, upgrading to |
The duration_float feature will arrive in Rust 1.38.0 stable. rust-lang/rust#54361
This adds `Duration::{as_secs_f64, as_secs_f32, from_secs_f64, from_secs_f32, mul_f64, mul_f32, div_f64, div_f32}` methods. They are based on `duration_float`](rust-lang/rust#54361) feature of the standard library that stabilized on Rust 1.39.
This adds `Duration::{as_secs_f64, as_secs_f32, from_secs_f64, from_secs_f32, mul_f64, mul_f32, div_f64, div_f32}` methods. They are based on `duration_float`](rust-lang/rust#54361) feature of the standard library that stabilized on Rust 1.38.
This adds `Duration::{as_secs_f64, as_secs_f32, from_secs_f64, from_secs_f32, mul_f64, mul_f32, div_f64, div_f32}` methods. They are based on [`duration_float`](rust-lang/rust#54361) feature of the standard library that stabilized on Rust 1.38.
21: Add duration_float methods r=taiki-e a=taiki-e This adds `Duration::{as_secs_f64, as_secs_f32, from_secs_f64, from_secs_f32, mul_f64, mul_f32, div_f64, div_f32}` methods. They are based on [`duration_float`](rust-lang/rust#54361) feature of the standard library that stabilized on Rust 1.38. Co-authored-by: Taiki Endo <te316e89@gmail.com>
Rust PRs: #52813, #59102
This feature adds the following float related methods to
Duration
:as_secs_f64(&self) -> f64
as_secs_f32(&self) -> f32
from_secs_f64(secs: f64) -> Duration
from_secs_f32(secs: f32) -> Duration
mul_f64(self, rhs: f64) -> Duration
mul_f32(self, rhs: f32) -> Duration
div_f64(self, rhs: f64) -> Duration
div_f32(self, rhs: f64) -> Duration
div_duration
methods are tracked in #63139.The text was updated successfully, but these errors were encountered: