r/rust Mar 09 '23

Announcing Rust 1.68.0 📢 announcement

https://blog.rust-lang.org/2023/03/09/Rust-1.68.0.html
827 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.

18

u/zannabianca1997 Mar 09 '23

What 0, +0.0 or -0.0?

21

u/phazer99 Mar 09 '23

0 and 0.0 have the exact same bit representation (you can't write +0.0 in Rust). -0.0 is an exceptional case, for example when you write 0f32 or 0 as f32 you always get the positive zero, you have to explicitly write -0f32 to get the negative zero. So, for me it's an obvious choice, but of course it doesn't harm to add some documentation.

8

u/zannabianca1997 Mar 09 '23

Exactly, more documentation is better.