Title: Implement `str` to `int` conversion by kmr-srbh · Pull Request #2599 · lcompilers/lpython · GitHub
Open Graph Title: Implement `str` to `int` conversion by kmr-srbh · Pull Request #2599 · lcompilers/lpython
X Title: Implement `str` to `int` conversion by kmr-srbh · Pull Request #2599 · lcompilers/lpython
Description: Resolves #2554 Implement basic string to integer conversion using CharacterToInteger casting, which I believe is a part of LFortran, but was not implemented here in LPython. Working from lpython import i8, i16, i32, i64 int8: i8 = i8("100") int16: i16 = i16("100") int32: i32 = i32("100") int64: i64 = i64("100") print("int8:", int8) print("int16:", int16) print("int32:", int32) print("int64:", int64) print() print("int8 + i8(10):", int8 + i8(10)) print("int16 * i16(2):", int16 * i16(2)) print("int32 - 50:", int32 - 50) print("int64 / i64(2):", int64 / i64(2)) (base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py int8: 100 int16: 100 int32: 100 int64: 100 int8 + i8(10): 110 int16 * i16(2): 200 int32 - 50: 50 int64 / i64(2): 5.00000000000000000e+01 ASR int32: (Variable 2 int32 [] Local (Cast (StringConstant "100" (Character 1 3 ()) ) CharacterToInteger (Integer 4) (IntegerConstant 100 (Integer 4)) ) (IntegerConstant 100 (Integer 4)) Default (Integer 4) () Source Public Required .false. ), int64: (Variable 2 int64 [] Local (Cast (StringConstant "100" (Character 1 3 ()) ) CharacterToInteger (Integer 8) (IntegerConstant 100 (Integer 8)) ) (IntegerConstant 100 (Integer 8)) Default (Integer 8) () Source Public Required .false. ), Tasks Throw a semantic error when an invalid literal is passed. While this can be handled while casting, it is not very clean to do it there. I request guidance on where the error should be thrown. Throw an error when an integer larger or smaller than the upper and lower bounds is passed as a valid string. I request guidance on where it should be handled. Handle integers with other bases. I doubt whether the types i8, i16, etc even take a 2nd argument. Even when several arguments are passed, only the 1st is dealt with and errors related to the same are thrown.
Open Graph Description: Resolves #2554 Implement basic string to integer conversion using CharacterToInteger casting, which I believe is a part of LFortran, but was not implemented here in LPython. Working from lpython im...
X Description: Resolves #2554 Implement basic string to integer conversion using CharacterToInteger casting, which I believe is a part of LFortran, but was not implemented here in LPython. Working from lpython im...
Opengraph URL: https://github.com/lcompilers/lpython/pull/2599
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a879f61f-06c3-b2a3-5ba4-1de2cdc6e63f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AEE0:272E5B:711DD6E:9ABA0A2:69787A32 |
| html-safe-nonce | 3fb30fdeab99911a1988ac821a4b14ec09242fefb402bc4d0634dc8a5629062b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUUwOjI3MkU1Qjo3MTFERDZFOjlBQkEwQTI6Njk3ODdBMzIiLCJ2aXNpdG9yX2lkIjoiNTUwODM5ODkxMjk4MjUxNDIyNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 64f01909c8a28f488daf3e995774c455b33d5e79e66b9e824a09aff3897de1ba |
| hovercard-subject-tag | pull_request:1765978750 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/lcompilers/lpython/pull/2599/files |
| twitter:image | https://avatars.githubusercontent.com/u/151380951?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/151380951?s=400&v=4 |
| og:image:alt | Resolves #2554 Implement basic string to integer conversion using CharacterToInteger casting, which I believe is a part of LFortran, but was not implemented here in LPython. Working from lpython im... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2981c597c945c1d90ac6fa355ce7929b2f413dfe7872ca5c435ee53a24a1de50 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/lcompilers/lpython git https://github.com/lcompilers/lpython.git |
| octolytics-dimension-user_id | 96538276 |
| octolytics-dimension-user_login | lcompilers |
| octolytics-dimension-repository_id | 442864346 |
| octolytics-dimension-repository_nwo | lcompilers/lpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 442864346 |
| octolytics-dimension-repository_network_root_nwo | lcompilers/lpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 520b65a872113b919c1bbdb03834a50af15859fd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width