When rounding very small numbers to some decimal places, e.g round(1.234567e-14, 2) , the result is NaN.
Not specifying decimals - round(1.234567e-14) - gives a correct result of 0.
Does someone know if that is a wanted behaviour or a bug?
1 Like
This is a bug . The implementation of the round
function in p5.js
is a horrible horrible idea :
p5.prototype.round = function(n, decimals) {
if (!decimals) {
return Math.round(n);
}
return Number(Math.round(n + 'e' + decimals) + 'e-' + decimals);
};
performing a multiplication and division by powers of 10 using string concatenation and conversion from string to Number is quite possibly the worst idea I’ve ever seen realized in javascript.
3 Likes