divide_and_conquer.power

Functions

actual_power(a, b)

Function using divide and conquer to calculate a^b.

power(→ float)

Module Contents

divide_and_conquer.power.actual_power(a: int, b: int)

Function using divide and conquer to calculate a^b. It only works for integer a,b.

Parameters:
  • a – The base of the power operation, an integer.

  • b – The exponent of the power operation, a non-negative integer.

Returns:

The result of a^b.

Examples: >>> actual_power(3, 2) 9 >>> actual_power(5, 3) 125 >>> actual_power(2, 5) 32 >>> actual_power(7, 0) 1

divide_and_conquer.power.power(a: int, b: int) float
Parameters:
  • a – The base (integer).

  • b – The exponent (integer).

Returns:

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