This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
kse-02/instrumented/exponentiation.py

19 lines
644 B
Python
Raw Permalink Normal View History

2023-11-13 15:33:20 +00:00
def exponentiation_instrumented(baseNumber: int, power: int) -> float:
2023-11-13 15:33:20 +00:00
assert (not ((baseNumber == 0) or (power <= 0)))
answer = None
if evaluate_condition(1, 'Gt', power, 1):
halfAnswer = exponentiation_instrumented(baseNumber, (power // 2))
answer = (halfAnswer * halfAnswer)
if evaluate_condition(2, 'Eq', (power % 2), 1):
answer *= baseNumber
elif evaluate_condition(3, 'Eq', power, 1):
answer = baseNumber
elif evaluate_condition(4, 'Eq', power, 0):
answer = 1
else:
answer = (1 / exponentiation_instrumented(baseNumber, abs(power)))
return answer