3 ms·
well you shouldn't expect much if you are comparing floats to doubles
by shultays 3y ago
well you shouldn't expect much if you are comparing floats to doubles
- spacechild1 3y agoTrue, but it's an easy mistake to make.
- tialaramex 3y agoIt's an easy mistake to make in C (and C++) because of their lackadaisical approach to type safety. In Rust if we insist we want to compare an f32 (what C would call float) to an f64 (double), the language says it doesn't have a way to do that, highlighting our mistake. If we just try to compare an f32 with value 0.7 against 0.7, the type inference concludes 0.7 is also an f32 so it's equal, and if we do the same with an f64, this time by inference 0.7 is an f64 and so again it's equal.
- spacechild1 3y agoRust's behavior makes so much more sense! IMO, implicit conversions is one of C++ biggest weaknesses. Yes, it may save some keystrokes, but it can easily lead to subtle (or not so subtle) bugs.
- kragen 3y agoagreed