Skip to content

Create 8. String to Integer (atoi).md#23

Merged
Mike0121 merged 2 commits intomainfrom
8.-String-to-Integer-(atoi)
Nov 1, 2025
Merged

Create 8. String to Integer (atoi).md#23
Mike0121 merged 2 commits intomainfrom
8.-String-to-Integer-(atoi)

Conversation

@Mike0121
Copy link
Copy Markdown
Owner

@Mike0121 Mike0121 commented Jun 4, 2024

Copy link
Copy Markdown

@hayashi-ay hayashi-ay left a comment

Choose a reason for hiding this comment

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

Pythonでやるならまあいいかなと思います。atoiはlibcの関数でint型の範囲内でオーバーフロー判定などをしようとするならもう少し考えることが増えるかなという感じです。

https://opensource.apple.com/source/Libc/Libc-262.2.12/stdlib/strtol.c.auto.html

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

is_negativeとかの方が良いかなと思います。

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.

ありがとうございます。flagで片付けてしまうことがあるので、覚えておきます。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

なんか命名がしっくりこないです。あまりfinalをつけることによって意味が増えていないと思います。あとは、finalといいつつINTの範囲を超える場合はMAX_INT、MIN_INTが返されているなという感想を持ちました。

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.

あまり良い変数名が思いつかなかったので、問題文からそのまま取ってきてしまいました。処理の内容踏まえると、digits_integerとかが良いでしょうかね。

@liquo-rice
Copy link
Copy Markdown

Pythonでやるならまあいいかなと思います。atoiはlibcの関数でint型の範囲内でオーバーフロー判定などをしようとするならもう少し考えることが増えるかなという感じです。

https://opensource.apple.com/source/Libc/Libc-262.2.12/stdlib/strtol.c.auto.html

他にはこれとか。https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/llvm-project/libc/src/__support/str_to_integer.h;l=72;drc=b6bc9d72f65a5086f310f321e969d96e9a559e75

@Mike0121 Mike0121 merged commit fbf39cb into main Nov 1, 2025
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