Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Char can't be converted to in128 #12957

Closed
meatball133 opened this issue Jan 15, 2023 · 1 comment · Fixed by #12958
Closed

Char can't be converted to in128 #12957

meatball133 opened this issue Jan 15, 2023 · 1 comment · Fixed by #12958
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric

Comments

@meatball133
Copy link
Contributor

Bug Report

On a problem similar to finding if a numbers is a Armstrong number or not there you have to iterate over a string which results in chars, these chars has to be converted to int and in some cases they need to be raised by a very high value, meaning you can end up with really high numbers. Since char can't be converted directly to int128 but first int and then int128, would it be easier if chars just could be converted to int128. I know that this is a bit of a rare case but still feels like char should be able to be converted to int128.

Code example:

Crystal 1.7:

input == number.chars.reduce(0_i128) { |acc, i| acc + i.to_i.to_i128 ** length }

My proposed changes:

input == number.chars.reduce(0_i128) { |acc, i| acc + i.to_i128 ** length }
@meatball133 meatball133 added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jan 15, 2023
@straight-shoota
Copy link
Member

Char has methods for all other interger types, so this makes sense for completeness. Should cover both Int128 and UInt128, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:numeric
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants