For example, originally I have code like this:
function(x,y){
let z=x+y;
.
.
.
}
later I found y must be the same as x, and want to refactor x+y to x * 2, but need to ensure the behaviour of whole program is the same before and after refactoring. Is x+x identical to x*2? I don’t know if + and * uses different calculation mechanisms and hence results in rounding to different results.
I tested:
for(let i=0.01;i<100;i++){
if(i+i!=i*2){
console.log(i);
break;
}
}
seems correct for some ranges of i, but don’t know if it is true for all float numbers.