-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2178 from Smit-create/i-2174
Fix unsigned to signed int cast
- Loading branch information
Showing
4 changed files
with
32 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
from lpython import u16, i32 | ||
from lpython import u16, i32, u8, u32, u64 | ||
|
||
# test issue 2170 | ||
|
||
i : i32 | ||
u : u16 = u16(32768) | ||
x : i32 | ||
u_1 : u16 = u16(32768) | ||
u_2 : u8 = u8(24) | ||
u_3 : u32 = u32(32768) | ||
u_4 : u64 = u64(32768) | ||
|
||
for i in range(i32(u)): | ||
x = i * 2 | ||
assert u_1 == u16(32768) | ||
assert u_2 == u8(24) | ||
assert u_3 == u32(32768) | ||
assert u_4 == u64(32768) | ||
|
||
print(u_1, u_2, u_3, u_4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from lpython import u16, i32, u8, u16, u64, i64, u32, i8 | ||
|
||
# test issue 2174 | ||
|
||
def f(): | ||
u: u16 = u16(32768) | ||
assert i32(u) == 32768 | ||
u1: u8 = u8(23) | ||
assert i8(u1) == i8(23) | ||
assert u16(u1) == u16(23) | ||
assert u32(u1) == u32(23) | ||
assert u64(u1) == u64(23) | ||
print(i8(u1), u16(u1), u32(u1), u64(u1)) | ||
assert i64(u1) == i64(23) | ||
assert i64(u) == i64(32768) | ||
assert i32(u1) == 23 | ||
print(i64(u), i32(u)) | ||
|
||
f() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters