Reputation: 13
I used python math.floor() for calculations but found that it was different from what I thought more. The code is as follows:
import math
x=math.floor(-4.1)**math.floor(-3.1)**math.floor(2.1)
y=-5**-4**2
print(x,y)
Why are the operation results of x and Y are not the same?
Upvotes: 1
Views: 73
Reputation: 117691
Because -a**n
and (-a)**n
are not the same. The first becomes -(a**n)
.
So when you write -5**...
and math.floor(-4.1)**...
they are not the same either.
If we fix this we get:
>>> x=math.floor(-4.1)**math.floor(-3.1)**math.floor(2.1)
>>> y=(-5)**(-4)**2
>>> print(x,y)
152587890625 152587890625
Upvotes: 3