Skip to content

Commit 4c26959

Browse files
committed
Implement runtime round function
1 parent 0c5ea37 commit 4c26959

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/runtime/lpython_builtin.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,13 @@ def oct(n: i32) -> str:
173173
n = n//8
174174
res += _values[remainder]
175175
return prep + res[::-1]
176+
177+
178+
def round(value: f64) -> i32:
179+
"""
180+
Rounds a floating point number to the nearest integer.
181+
"""
182+
if abs(value - int(value)) <= 0.5:
183+
return int(value)
184+
else:
185+
return int(value) + 1

0 commit comments

Comments
 (0)