Closed blueloveTH closed 1 year ago
Previously, int pow only considers positive operands. However, 2 ** -1 could be 0.5 which is a float number.
int
2 ** -1
0.5
This pr uses quick pow algorithm which is of O(log2N) complexity instead of O(N) and handles negative operand. Now these examples work as expected.
O(log2N)
O(N)
>>> 2 ** -1 0.500000 >>> 3** -2 0.111111 >>> 1 ** 0 1 >>> 2 ** 8 256
Previously,
int
pow only considers positive operands. However,2 ** -1
could be0.5
which is a float number.This pr uses quick pow algorithm which is of
O(log2N)
complexity instead ofO(N)
and handles negative operand. Now these examples work as expected.