Imagine that an inexperienced programmer tries to compare 2 floats for equivalence:
a = 0.01
b = 0.1 ** 2
print(a == b)
Is there any language that would throw an exception on such foolishness? Or a way to override the default behaviour in python and/or javascript?
If not, what is the reason behind language design decision to allow the operation?
EDIT: Looks like I've been accused of suggesting to make comparisons of floats impossible. I have nothing against
a < b
or float_eq(a, b)
. It's just that most people have very different intuition about what ==
, !=
, >=
and <=
operators are supposed to do from what they actually do with float numbers. There are various precedents in language design to prevent some of the dumber mistakes people tend to make, like disallowing if(a=b)
in python or use strict
in perl.