pikasTech / PikaPython

An ultra-lightweight Python interpreter that runs with only 4KB of RAM, zero dependencies. It is ready to use out of the box without any configuration required and easy to extend with C. Similar project: MicroPython, JerryScript.
http://pikapython.com/
MIT License
1.45k stars 132 forks source link

Fix a bug of _OP_POW #319

Closed blueloveTH closed 1 year ago

blueloveTH commented 1 year ago

Previously, int pow only considers positive operands. However, 2 ** -1 could be 0.5 which is a float number.

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.

>>> 2 ** -1
0.500000
>>> 3** -2
0.111111
>>> 1 ** 0
1
>>> 2 ** 8
256