I was writing a code to calculate number of digits in a given whole number.
I was initially using
math.log(num,10)
but found out it was giving incorrect(approximate) value at num = 1000
math.log(1000,10)
>2.9999999999999996
I understand that the above might be due to the floating point arithmetic in computers being done differently but the same, however, works flawlessly using math.log10
math.log10(1000)
>3.0
Is it correct to assume that log10
is more accurate than log
and to use it wherever log base 10 is involved instead of going with the more generalized log
function?