summaryrefslogtreecommitdiff
path: root/ports/unix/modtime.c
diff options
context:
space:
mode:
authorstijn <stijn@ignitron.net>2020-04-09 09:05:48 +0200
committerDamien George <damien.p.george@gmail.com>2020-04-18 22:36:14 +1000
commit0ba68f8a1dae84de950420aebf8ad46582a38e66 (patch)
treec996a9b3d26f58b286ef6f9deb508de141b66574 /ports/unix/modtime.c
parentb909e8b2dd007d8e7d61547768518b29bb4f833c (diff)
all: Fix implicit floating point promotion.
Initially some of these were found building the unix coverage variant on MacOS because that build uses clang and has -Wdouble-promotion enabled, and clang performs more vigorous promotion checks than gcc. Additionally the codebase has been compiled with clang and msvc (the latter with warning level 3), and with MICROPY_FLOAT_IMPL_FLOAT to find the rest of the conversions. Fixes are implemented either as explicit casts, or by using the correct type, or by using one of the utility functions to handle floating point casting; these have been moved from nativeglue.c to the public API.
Diffstat (limited to 'ports/unix/modtime.c')
-rw-r--r--ports/unix/modtime.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/ports/unix/modtime.c b/ports/unix/modtime.c
index 126aec30c..16152152a 100644
--- a/ports/unix/modtime.c
+++ b/ports/unix/modtime.c
@@ -61,7 +61,7 @@ static inline int msec_sleep_tv(struct timeval *tv) {
#endif
#if defined(MP_CLOCKS_PER_SEC)
-#define CLOCK_DIV (MP_CLOCKS_PER_SEC / 1000.0F)
+#define CLOCK_DIV (MP_CLOCKS_PER_SEC / MICROPY_FLOAT_CONST(1000.0))
#else
#error Unsupported clock() implementation
#endif
@@ -84,7 +84,7 @@ STATIC mp_obj_t mod_time_clock(void) {
// float cannot represent full range of int32 precisely, so we pre-divide
// int to reduce resolution, and then actually do float division hoping
// to preserve integer part resolution.
- return mp_obj_new_float((float)(clock() / 1000) / CLOCK_DIV);
+ return mp_obj_new_float((clock() / 1000) / CLOCK_DIV);
#else
return mp_obj_new_int((mp_int_t)clock());
#endif
@@ -95,8 +95,8 @@ STATIC mp_obj_t mod_time_sleep(mp_obj_t arg) {
#if MICROPY_PY_BUILTINS_FLOAT
struct timeval tv;
mp_float_t val = mp_obj_get_float(arg);
- double ipart;
- tv.tv_usec = round(modf(val, &ipart) * 1000000);
+ mp_float_t ipart;
+ tv.tv_usec = MICROPY_FLOAT_C_FUN(round)(MICROPY_FLOAT_C_FUN(modf)(val, &ipart) * MICROPY_FLOAT_CONST(1000000.));
tv.tv_sec = ipart;
int res;
while (1) {