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

Could from_f32() etc. be const-fn? #9

Closed
Boscop opened this issue Apr 9, 2018 · 5 comments
Closed

Could from_f32() etc. be const-fn? #9

Boscop opened this issue Apr 9, 2018 · 5 comments
Labels
awaiting stabilization Resolving this issue requires stabilization of unstable nightly Rust features enhancement

Comments

@Boscop
Copy link

Boscop commented Apr 9, 2018

Could from_f32() etc. be const-fn? Would be useful for halving the size of float data in static arrays in demoscene intros.

@starkat99
Copy link
Owner

Once const fn is stabilized, I definitely think all of the constructors should be! Right now there's some pretty heated debate currently still happening on the stabilization tracking issue. I'd rather wait for stabilization, but if needed sooner, I can certainly add another nightly-only feature flag in the interim.

@branchmispredictor
Copy link

Hi there, now that const fn is stable, are there any plans to make from_f32 a const fn? Thanks!

@starkat99
Copy link
Owner

If I remember correctly, it's just waiting on rust-lang/rust#57241 to make f32/f64::from/to_bits const, but there's unresolved issues to be addressed there

@starkat99 starkat99 added the awaiting stabilization Resolving this issue requires stabilization of unstable nightly Rust features label Oct 8, 2021
@starkat99
Copy link
Owner

With the release of Rust 1.56, mem::transmute was const stabilized. This allowed me to implement const conversions as new functions (from_f32_const instead of just from_f32). This allows existing from_f32 functions to continue using hardware intrinsics when available.

I'll be holding off on publishing a new version until the above linked issue is const stabilized so that to_bits/from_bits can be used again and avoid those unsafe mem::transmute calls. If anyone wants access sooner without using a git dependency, just say so and I'll publish a pre-release.

@starkat99
Copy link
Owner

It looks like to_bits/from_bits will take a lot longer to stabilize due to general float soudness concerns. Went ahead and released current const conversions as-is with mem::transmute implementation for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting stabilization Resolving this issue requires stabilization of unstable nightly Rust features enhancement
Projects
None yet
Development

No branches or pull requests

3 participants