Skip to content

Commit a1409d1

Browse files
dhalberttannewt
authored andcommitted
redo time.monotonic() to avoid double precision
1 parent 4f4ddf0 commit a1409d1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

shared-bindings/time/__init__.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
//| :rtype: float
5353
//|
5454
STATIC mp_obj_t time_monotonic(void) {
55-
return mp_obj_new_float(common_hal_time_monotonic() / 1000.0);
55+
uint64_t time64 = common_hal_time_monotonic();
56+
// 4294967296 = 2^32
57+
return mp_obj_new_float(((uint32_t) (time64 >> 32) * 4294967296.0f + (uint32_t) (time64 & 0xffffffff)) / 1000.0f);
5658
}
5759
MP_DEFINE_CONST_FUN_OBJ_0(time_monotonic_obj, time_monotonic);
5860

0 commit comments

Comments
 (0)