For a project I am working on, I need to convert from bool to f32 and f64.
There are lossless conversions, from true to 1.0 and false to 0.0 - I think?
I can convert from bool to f64 by converting to i32 first.
Why is there no direct way to convert from bool to f32 or f64?
Hey, thanks a lot for your answer. I would prefer not to write a function with an if, as it might be possible to optimize this using other instructions. What do you think?
Rust depends on optimizations for a lot of abstractions to come out zero-cost. E.g. in what @frewsxcv linked, convert2 and convert3 are pretty different without optimizations, but compile to the same instructions with opt-level=3. I'm very much prefer convert3, so I find it very significant that it turns out the same in release mode (which is using opt-level=3).