aboutsummaryrefslogtreecommitdiff
path: root/shared-bindings/time/__init__.c
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2017-10-16 23:48:26 -0400
committerScott Shawcroft <scott@tannewt.org>2017-10-17 10:02:16 -0700
commita1409d1432ea4280293749b3a2bb5c2278fda609 (patch)
treeb08f01997614c9dc6c6034e7dacb3b1528b1730a /shared-bindings/time/__init__.c
parent4f4ddf00dcce450aaa79da2cdab25fad674926f9 (diff)
redo time.monotonic() to avoid double precision2.1.0
Diffstat (limited to 'shared-bindings/time/__init__.c')
-rw-r--r--shared-bindings/time/__init__.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c
index 105758951..6956cc4e6 100644
--- a/shared-bindings/time/__init__.c
+++ b/shared-bindings/time/__init__.c
@@ -52,7 +52,9 @@
//| :rtype: float
//|
STATIC mp_obj_t time_monotonic(void) {
- return mp_obj_new_float(common_hal_time_monotonic() / 1000.0);
+ uint64_t time64 = common_hal_time_monotonic();
+ // 4294967296 = 2^32
+ return mp_obj_new_float(((uint32_t) (time64 >> 32) * 4294967296.0f + (uint32_t) (time64 & 0xffffffff)) / 1000.0f);
}
MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_obj, time_monotonic);