3 ms·
Here's something that would probably help lessen the confusion: don't allow or atleast warn about implicit conversions in binary floats in source code literals.
by pvdebbe 10y ago
Here's something that would probably help lessen the confusion: don't allow or atleast warn about implicit conversions in binary floats in source code literals.
float foo = 0.3; // warning: invalid binary float value
float bar = 0.3f; // ok, converts into nearest bin float
decimal qux = 0.3m; // ok
decimal feh = 0.3; // why not; will be exactly 0.3
All in all, languages go for decimal floats by default but then the implicit conversions ruin it for everybody who's still learning.
- septimus111 10y agoGood suggestion, but it still wouldn't prevent beginners from just learning the 0.3f notation as an idiom and skipping the explanation. The trouble with floats is that understanding them depends on knowledge of binary, scientific notation, etc. It's a lot for someone who is only just getting to grips with how a program works.
- deleted 10y ago[deleted]