I ran into a weird situation earlier. I wrote:
if rand::random() < self.food_chance {...}
(self.food_chance is of type f32)
and I got a type inferencing error:
|
71 | if rand::random() < self.food_chance {
| ^^^^^^^^^^^^ cannot infer type for `T`
However this code compiles
if self.food_chance > rand::random() {...}
And I'm left wondering. Is there a reason for this behaviour? Is it even intended behaviour?
I know a little bit about type inferencing theory, and I know that most of the algorithms are agnostic to lhs/rhs, so I'm tempted to think this is expected behaviour rather than straight up a bug.
I tried searching around, but I never got anything close to this.