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

Tracking issue for the convert::FloatToInt trait #67057

Open
SimonSapin opened this issue Dec 5, 2019 · 2 comments
Open

Tracking issue for the convert::FloatToInt trait #67057

SimonSapin opened this issue Dec 5, 2019 · 2 comments
Labels
A-floating-point Area: Floating point numbers and arithmetic B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. Libs-Tracked Libs issues that are tracked on the team's project board. S-tracking-perma-unstable Status: The feature will stay unstable indefinitely. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

SimonSapin commented Dec 5, 2019

PR #66841 adds this supporting trait for the {f32,f64}::approx_unchecked_to method (tracking issue: #67058) to the core::convert and std::convert modules:

mod private {
    pub trait Sealed {}
}
pub trait FloatToInt<Int>: private::Sealed + Sized {
    #[doc(hidden)]
    unsafe fn approx_unchecked(self) -> Int;
}

// Macro-generated for all combinations of primitive integer
// and primitive floating point types:
impl FloatToInt<$Int> for $Float {}

The name and location (and usage of the sealed-trait pattern) are chosen to allow later adding additional methods with different conversion semantics between those types, as proposed in https://internals.rust-lang.org/t/pre-rfc-add-explicitly-named-numeric-conversion-apis/11395

@jonas-schievink jonas-schievink added B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Dec 5, 2019
@KodrAus KodrAus added Libs-Tracked Libs issues that are tracked on the team's project board. A-floating-point Area: Floating point numbers and arithmetic labels Jul 30, 2020
@dodomorandi
Copy link

What's the current state of the art? Is it just a matter of low priority respect to other things?

And even if it is not the best place to ask: this will be the foundation for one (or more) RFC(s) to expose safe APIs like in the pre-RFC?

@SimonSapin
Copy link
Contributor Author

SimonSapin commented Dec 19, 2020

The to_int_unchecked method of f32 and f64 were previously tracked at #67058 and are stable since 1.44. Technically only their supporting trait is tracked here.

For the wider idea of adding several conversion methods, what’s needed now is someone to champion it. Polish https://internals.rust-lang.org/t/pre-rfc-add-explicitly-named-numeric-conversion-apis/11395 (especially around prior art and alternatives) and formally propose and RFC, drive the discussion, etc. I’ve been meaning to since drafting it but you know, life happened. It doesn’t need to be me though ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-floating-point Area: Floating point numbers and arithmetic B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. Libs-Tracked Libs issues that are tracked on the team's project board. S-tracking-perma-unstable Status: The feature will stay unstable indefinitely. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants