0

Given 3^5 (3**5 or 3*3*3*3*3) = 243.

Why/how does Ruby do the following:

n = 243
Math.log(n,3)
returns: 
4.999999999999999

Math.log(243)/Math.log(3)
returns: 
4.999999999999999

3**Math.log(n,3)
returns:
242.99999999999977

That last one really gets me. Something is going wrong here? I'm missing something? Both?

Thanks!

1 Answers1

1

Values are not wrong, this is because floating point precision is limited.

Vasfed
  • 18,013
  • 10
  • 47
  • 53