You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Funny enough, the people are aware of this problem:
error[E0606]: casting `bool` as `f64` is invalid
--> src/main.rs:3:20
|
3 | println!("{}", true as f64);
| ^^^^^^^^^^^
|
= help: cast through an integer first
I think there's a valid reason for this, but let's see
But what the actual hell?! bool and a number are conceptually different, why allow any of those conversions? IMO the only sensible conversion is if x { 1 } else { 0 } (with compiler optimization). This is converting apples into eggs... Anyway, the ship has sailed.
Activity
hellow554 commentedon Jul 3, 2020
Funny enough, the people are aware of this problem:
I think there's a valid reason for this, but let's see
Mark-Simulacrum commentedon Jul 3, 2020
Integer casts are essentially no-ops since the bit pattern is the same, but casting to a float would be less obvious/straightforward, IMO.
I guess you expect 1.0 as the result, same as casting through an integer gets you?
leonardo-m commentedon Jul 4, 2020
I expect f64::from(bool) to have about the same semantics of f64::from(u32::from(bool)), yes.
workingjubilee commentedon Apr 29, 2021
Which zero to return?
leonardo-m commentedon Apr 29, 2021
The same as f32::from(0_u8), that should be a +0.0.
Kixunil commentedon Mar 9, 2023
Doc says it's implemented, so this should be closed?
But what the actual hell?!
bool
and a number are conceptually different, why allow any of those conversions? IMO the only sensible conversion isif x { 1 } else { 0 }
(with compiler optimization). This is converting apples into eggs... Anyway, the ship has sailed.est31 commentedon Mar 9, 2023
This should be closed now, yes. Implementation PR was #100390.