starkat99 / half-rs

Half-precision floating point types f16 and bf16 for Rust.
https://docs.rs/half/
Other
233 stars 52 forks source link

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

Closed Boscop closed 2 years ago

Boscop commented 6 years ago

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

starkat99 commented 6 years ago

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 commented 3 years ago

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

starkat99 commented 3 years ago

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

starkat99 commented 2 years ago

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 commented 2 years ago

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.