mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-11 17:19:48 +00:00
Update power.py
This commit is contained in:
parent
d1f4ea4676
commit
53b5e81166
@ -32,6 +32,17 @@ def power(a: int, b: int) -> float:
|
||||
:param a: The base (integer).
|
||||
:param b: The exponent (integer).
|
||||
:return: The result of a^b, as a float for negative exponents.
|
||||
|
||||
>>> power(4,6)
|
||||
4096
|
||||
>>> power(2,3)
|
||||
8
|
||||
>>> power(-2,3)
|
||||
-8
|
||||
>>> power(2,-3)
|
||||
0.125
|
||||
>>> power(-2,-3)
|
||||
-0.125
|
||||
"""
|
||||
if b < 0:
|
||||
return 1 / actual_power(a, -b)
|
||||
|
Loading…
x
Reference in New Issue
Block a user