Why Vector.isZero() is checking whether a vector length is smaller than 0.0001? Why this arbitrary number and not e.g. 0.00000001?
(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/
Any idea on how to go about this in JavaScript? The binary representation of the float isn't as easy to come by (compared to C, for example), but I wonder if you couldn't get a decent approximation with Math.log2.
For example, you can get an array of the bytes in a number `n` with this:
new Uint8Array((new Float64Array([n])).buffer)