Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.

Commit 13ff1e2

Browse files
Remove round, it's in the stdlib
1 parent 89e8305 commit 13ff1e2

File tree

5 files changed

+6
-32
lines changed

5 files changed

+6
-32
lines changed

stdlib_extensions/builtins/__init__.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from ._bytes import bytes, to_bytes
33
from ..syscalls.filesystem import read_from_stdin
44
from ._hash import custom_hash
55
from ._types import Optional
6-
from ._math import divmod, round
6+
from ._math import divmod
77
from ._custom_equality import ___eq__
88

99

stdlib_extensions/builtins/_math.mojo

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,3 @@ fn divmod(a: Int, b: Int) -> Tuple[Int, Int]:
44

55
fn divmod(a: Int64, b: Int64) -> Tuple[Int64, Int64]:
66
return a // b, a % b
7-
8-
9-
fn round(number: Float64) -> Int:
10-
var floor = number // 1
11-
var remainder = number - floor
12-
if remainder > 0.5:
13-
return int(floor + 1)
14-
elif remainder < 0.5:
15-
return int(floor)
16-
else:
17-
# rounding to the nearest even number
18-
if floor % 2 == 0:
19-
return int(floor)
20-
else:
21-
return int(floor + 1)

stdlib_extensions/datetime/_timedelta.mojo

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from ..builtins import divmod, round, list
1+
from ..builtins import divmod, list
22
from ..builtins.string import rjust, join
33
from ..builtins._generic_list import _cmp_list
44
from ..builtins import custom_hash
55
from utils.variant import Variant
6-
from math import abs
6+
from math import abs, round
77

88
# TODO: use this in the timedelta constructor
99
alias IntOrFloat = Variant[Int, Float64]
@@ -131,7 +131,7 @@ struct timedelta(CollectionElement, Stringable, Hashable):
131131
days, seconds = divmod(seconds, 24 * 3600)
132132
d += days
133133
s += seconds
134-
microseconds = round(microseconds + usdouble)
134+
microseconds = round(Float64(microseconds) + usdouble).to_int()
135135
# TODO: Manage floats
136136
# assert isinstance(s, int)
137137
# assert isinstance(microseconds, int)

stdlib_extensions/datetime/_utils.mojo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This file is taken from https://github.com/python/cpython/blob/main/Lib/_pydatet
77
It's just been converted to Mojo manually.
88
"""
99

10-
from ..builtins import list, divmod, round, abs
10+
from ..builtins import list, divmod
1111
from ..builtins.string import join
1212
from ..time import struct_time
1313
import math as _math
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ...stdlib_tests.utils import assert_true, assert_false, assert_equal
2-
from ...builtins import divmod, round
2+
from ...builtins import divmod
33

44

55
def test_divmod():
@@ -14,16 +14,5 @@ def test_divmod():
1414
assert_equal(b, -1)
1515

1616

17-
def test_round():
18-
assert_equal(round(-2.0), -2)
19-
assert_equal(round(-1.5), -2)
20-
assert_equal(round(-1.0), -1)
21-
assert_equal(round(-0.5), 0)
22-
assert_equal(round(0.0), 0)
23-
assert_equal(round(0.5), 0)
24-
assert_equal(round(1.0), 1)
25-
26-
2717
def run_tests():
2818
test_divmod()
29-
test_round()

0 commit comments

Comments
 (0)