Skip to content

50. Pow(x, n)#43

Open
5103246 wants to merge 1 commit intomainfrom
50-powx-n
Open

50. Pow(x, n)#43
5103246 wants to merge 1 commit intomainfrom
50-powx-n

Conversation

@5103246
Copy link
Copy Markdown
Owner

@5103246 5103246 commented Mar 21, 2026

return 0.0;
}

long long exp = n;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++11 以降は int64_t を使うことが多いと思います。


long long exp = n;

if (exp < 0) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

真の場合の処理と偽の場合の処理が対称になっているため、自分なら early return はしないと思います。

if (exp >= 0) {
    return myPowHelper(x, exp);
} else {
    return 1 / myPowHelper(x, -exp);
}

return 0.0;
}

long long exp = n;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exp という変数名は、標準ライブラリの std::exp と被っているため、避けたほうが良いかもしれません。
https://cpprefjp.github.io/reference/cmath/exp.html

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コメントありがとうございます。
標準ライブラリに std::exp があるんですね。以後、気を付けます。

@mamo3gr
Copy link
Copy Markdown

mamo3gr commented Mar 23, 2026

コメントされている箇所以外は、特に違和感ありませんでした 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants