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

String to int conversion in ASR #2554

Open
certik opened this issue Feb 24, 2024 · 4 comments · May be fixed by #2599
Open

String to int conversion in ASR #2554

certik opened this issue Feb 24, 2024 · 4 comments · May be fixed by #2599

Comments

@certik
Copy link
Contributor

certik commented Feb 24, 2024

Figure out a clean way to represent and implement string to int conversions in ASR.

Then figure out how to hook it up in LPython.

Discussed at https://lfortran.zulipchat.com/#narrow/stream/311866-LPython/topic/String.20to.20Int.20conversion.

@Shaikh-Ubaid
Copy link
Collaborator

It looks like we already have some support for string to int conversion.

% cat examples/expr2.py 
def main():
    x: str = "123"
    print(int(x))

main()
% python examples/expr2.py         
123
% lpython_in_main examples/expr2.py
123

@Shaikh-Ubaid
Copy link
Collaborator

I think we just need to polish the existing support.

@kmr-srbh
Copy link
Contributor

kmr-srbh commented Mar 25, 2024

@Shaikh-Ubaid I think we should support the conversion mechanism which intrinsic_int uses, for all the integer types we have. My main concern is that doing i32(int("12345")) is counterintuitive.

@kmr-srbh
Copy link
Contributor

The conversion mechanism for int needs to be improved too. It currently relies on std::stoi() and fails for anything larger than that. We only have to improve the BigInt library we already have.

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 a pull request may close this issue.

3 participants