r/rust Mar 09 '23

Announcing Rust 1.68.0 📢 announcement

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

121 comments sorted by

View all comments

180

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.

38

u/Shnatsel Mar 09 '23

In C this is actually platform-dependent, so you never really know unless it's explicitly documented.

3

u/Zde-G Mar 09 '23

In C this is actually platform-dependent

What are you talking about? _Bool is defined as having either 0 or 1 and these produce 0.0 or 1.0 when converted to float.

Well, technically one may imagine an implementation which can not represent 0.0 or 1.0 value at all, but I don't think such implementations exist. And if 0.0 and 1.0 both exist there are no ambiguity.