We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c79cb95 commit 456e4fbCopy full SHA for 456e4fb
divide_and_conquer/power.py
@@ -29,26 +29,14 @@ def actual_power(a: int, b: int):
29
return a * half * half
30
31
def power(a: int, b: int) -> float:
32
- """
+ """
33
:param a: The base (integer).
34
:param b: The exponent (integer).
35
:return: The result of a^b, as a float for negative exponents.
36
-
37
- >>> power(4,6)
38
- 4096
39
- >>> power(2,3)
40
- 8
41
- >>> power(-2,3)
42
- -8
43
- >>> power(2,-3)
44
- 0.125
45
- >>> power(-2,-3)
46
- -0.125
47
"""
48
if b < 0:
49
- return 1 / actual_power(a, b)
+ return 1 / actual_power(a, -b)
50
return actual_power(a, b)
51
52
53
if __name__ == "__main__":
54
- print(power(-2, -3))
+ print(power(-2, -3)) #output -0.125
0 commit comments