language.core: implement round(value, width) (fixes #203).

This commit is contained in:
whitequark 2015-12-22 11:16:51 +08:00
parent 25188f0ca9
commit a250b5da21
1 changed files with 7 additions and 2 deletions

View File

@ -10,7 +10,7 @@ from functools import wraps
from artiq.coredevice.runtime import source_loader
__all__ = ["host_int", "int",
__all__ = ["host_int", "int", "host_round", "round",
"kernel", "portable", "syscall",
"set_time_manager", "set_watchdog_factory",
"ARTIQException",
@ -161,6 +161,11 @@ class int:
__lt__ = _compareop(host_int.__lt__, "__ge__")
__le__ = _compareop(host_int.__le__, "__gt__")
host_round = round
def round(value, width=32):
return int(host_round(value), width)
_ARTIQEmbeddedInfo = namedtuple("_ARTIQEmbeddedInfo",
"core_name function syscall")
@ -316,7 +321,7 @@ def seconds_to_mu(seconds, core=None):
"""
if core is None:
raise ValueError("Core device must be specified for time conversion")
return round64(seconds//core.ref_period)
return round(seconds//core.ref_period, width=64)
def mu_to_seconds(mu, core=None):