|
|
|
|
|
by matchu
3985 days ago
|
|
Dunno about this case, but probably because floating point arithmetic is a bitch. Try the following in Chrome's developer console: (0.3 - 0.1 - 0.1 - 0.1) === 0.0
> false
0.3 - 0.1 - 0.1 - 0.1
> -2.7755575615628914e-17
In order to get helpful results, we're gonna have to pick some semi-arbitrary epsilon. Still, my problem domain might require a different epsilon than they expect; even if they have a default, the API should allow me to specify my own choice of epsilon.They might also want to consider being more nuanced for the equals method than just taking the difference and comparing to zero. See http://floating-point-gui.de/errors/comparison/ |
|