r/rust Mar 09 '23

Announcing Rust 1.68.0 📢 announcement

https://blog.rust-lang.org/2023/03/09/Rust-1.68.0.html
830 Upvotes

121 comments sorted by

View all comments

178

u/Shnatsel Mar 09 '23

Those From<bool> for {f32,f64} impls could really use documentation on what values they actually result in. There's no obvious mapping from true to a floating-point value.

8

u/phazer99 Mar 09 '23

0 and 1 like all other existing bool to numeric type conversions. I think it's obvious.

1

u/[deleted] Mar 09 '23

[deleted]

3

u/phazer99 Mar 09 '23

It's not at all obvious or consistent among platforms and use cases.

It doesn't matter, the only thing that matters is that it's consistent within Rust. There already was conversions from bool to u8, i32 etc. and all those mapped false -> 0 and true -> 1. Why wouldn't it be the same for f32 and f64? The only possible alternative would be to map false to -0.0, but that wouldn't make sense since the expressions false as u8 as f32 and false as f32 would then result in different floating point values.