Skip to content

Commit 5ccc09c

Browse files
authored
Merge pull request #1587 from certik/floordiv
Implement floordiv for i16 and i8
2 parents c792719 + 860d530 commit 5ccc09c

File tree

77 files changed

+121
-81
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+121
-81
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ RUN(NAME expr_12 LABELS llvm c)
255255
RUN(NAME expr_13 LABELS llvm c
256256
EXTRAFILES expr_13b.c)
257257
RUN(NAME expr_14 LABELS cpython llvm c)
258+
RUN(NAME expr_15 LABELS cpython llvm c)
258259
RUN(NAME loop_01 LABELS cpython llvm c)
259260
RUN(NAME loop_02 LABELS cpython llvm c wasm wasm_x86 wasm_x64)
260261
RUN(NAME loop_03 LABELS cpython llvm c wasm wasm_x64)

integration_tests/expr_15.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from ltypes import i8, i16
2+
3+
def test_issue_1586():
4+
x4: i16
5+
y4: i16
6+
y4 = i16(10)
7+
x4 = i16(12345)
8+
assert x4//y4 == i16(1234)
9+
10+
a4: i8
11+
b4: i8
12+
a4 = i8(10)
13+
b4 = i8(123)
14+
assert b4//a4 == i8(12)
15+
16+
def check():
17+
test_issue_1586()
18+
19+
check()

src/runtime/lpython_builtin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,26 @@ def _lpython_floordiv(a: f32, b: f32) -> f32:
469469
resultf32 = f32(1.0) * f32(result) - f32(1.0)
470470
return resultf32
471471

472+
@overload
473+
def _lpython_floordiv(a: i8, b: i8) -> i8:
474+
r: f64 # f32 rounds things up and gives incorrect results
475+
r = float(a)/float(b)
476+
result: i8
477+
result = i8(r)
478+
if r >= 0.0 or f64(result) == r:
479+
return result
480+
return result - i8(1)
481+
482+
@overload
483+
def _lpython_floordiv(a: i16, b: i16) -> i16:
484+
r: f64 # f32 rounds things up and gives incorrect results
485+
r = float(a)/float(b)
486+
result: i16
487+
result = i16(r)
488+
if r >= 0.0 or f64(result) == r:
489+
return result
490+
return result - i16(1)
491+
472492
@overload
473493
def _lpython_floordiv(a: i32, b: i32) -> i32:
474494
r: f64 # f32 rounds things up and gives incorrect results

tests/reference/asr-array_01_decl-39cf894.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-array_01_decl-39cf894.stdout",
9-
"stdout_hash": "9a5b7daf71fa50d535cc4ed81bfbc307ffb5e0560317e8e08de0e70d",
9+
"stdout_hash": "5ecd298c183e6b4027f8f601a2b5d3963033ebf54bca582c982b5929",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-array_01_decl-39cf894.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/asr-array_02_decl-e8f6874.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-array_02_decl-e8f6874.stdout",
9-
"stdout_hash": "a89ba70977945aaa7de41e98302e8fae61815262e2f41e18222a0a80",
9+
"stdout_hash": "9fcfaf5cb7d6dfd6798902f102d41743c0c6c89180572345d886154f",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-array_02_decl-e8f6874.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/asr-bindc_02-bc1a7ea.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-bindc_02-bc1a7ea.stdout",
9-
"stdout_hash": "48b7a2efdd3ca69877638f9bf332aecea9638fb382e73ede9cce651e",
9+
"stdout_hash": "00799f9ef4a45d4c3e93d043b31f73f8038a4b82a4ee191f29b0467f",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/asr-bindc_02-bc1a7ea.stdout

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/reference/asr-cast-435c233.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "asr-cast-435c233.stdout",
9-
"stdout_hash": "0263f1538bbd3457f42a3bed5817bc098151059c3202305815940ac9",
9+
"stdout_hash": "17cc5e55a18b44793f2e153ef08fd85e279fb740ad6991a3d47665b8",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

0 commit comments

Comments
 (0)