Would scaling a float value by ten to preserve precision during a calculation be always precise?
This question only applies for any number involved being less than Math.pow (2,53)
and greater than Math.pow (10,-15)
, as Math.pow (10,16 ) > Math.pow (2,53)
I hope this clears some points
0.3 - 0.2 //0.09999999999999998
Is obvious unprecise
But doing the substraction on a scaled number
var a = 0.3;
var b = 0.2;
var l = Math.max ("".split.call(a,".")[1].length,"".split.call(b,".")[1].length);
var c;
a *= Math.pow (10,l);
b *= Math.pow (10,l);
c = a-b;
c /= Math.pow(10,l);
console.log(c); //0.1
Gives a " precise " result.
The Question is, is there any float value, matching the above mentioned criterias f<Math.pow(10,-15)
,when multiplied by a power of ten (where Math.pow ( 10 , n<16)<Math.pow(2,53)
), which does not result in the double value nearest
N(b)-N(a)?, when divided again by the same power of 10?
Like described in the snippet above.
This is only a question of interest, not about using this for actual calculations, I'm just curious
And sry for misunderstandings I`m not good in this Explanation thingy