1

why are there difference between * and **

def disk_area(radius):
    return 3.14*(radius**2)
7.065

Versus

def disk_area(radius):
    return 3.14*radius*radius
7.0649999999999995
iBug
  • 35,554
  • 7
  • 89
  • 134
Newbie
  • 11
  • 2
  • Floating point arithmetic is subject to errors due to the nature of the binary representation of floating point numbers. See https://stackoverflow.com/q/588004/ for example. – iz_ Oct 16 '19 at 03:32

1 Answers1

0

Exponent operator supports negative, fractional, and complex values:

3 ** -1
5 ** math.sqrt(2)
1j ** (1 + 1j)

You're not going to make any of those happen with * multiply operators, right?

iBug
  • 35,554
  • 7
  • 89
  • 134
  • but why one version gives 7.065 vs the other gave 7.0649999999999995. Sorry cant get it from your answer – Newbie Oct 16 '19 at 03:47
  • @Newbie [This](https://stackoverflow.com/q/588004/5958455) is what you want to read. – iBug Oct 16 '19 at 03:54