LC: https://leetcode-cn.com/problems/shu-zhi-de-zheng-shu-ci-fang-lcof/
    牛客: https://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00?tpId=13&&tqId=11165&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking

    1. 浮点型 快速幂
    2. 将底数转化为 分数计算,确保指数是正数;
    1. class Solution {
    2. public:
    3. double myPow(double x, int n) {
    4. if (x == 1 || n == 0) {
    5. return 1;
    6. }
    7. double sum = 1;
    8. long num = n;
    9. if (n < 0) {
    10. x = 1 / x;
    11. num = -num;
    12. }
    13. while (num) {
    14. if (num & 1) {
    15. sum *= x;
    16. }
    17. num >>= 1;
    18. x *= x;
    19. }
    20. return sum;
    21. }
    22. };