Update power.py

This commit is contained in:
Maxim Smolskiy 2025-02-09 20:45:56 +03:00 committed by GitHub
parent d1f4ea4676
commit 53b5e81166
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)