diff --git a/include/cmetrics/cmt_math.h b/include/cmetrics/cmt_math.h index 4a91f1a..dfa659a 100644 --- a/include/cmetrics/cmt_math.h +++ b/include/cmetrics/cmt_math.h @@ -30,24 +30,30 @@ static inline uint64_t cmt_math_d64_to_uint64(double val) { + uint64_t tmp; + if (isnan(val)) { - return 0; + /* we need to decide how to handle this */ } if (isinf(val)) { - return UINT64_MAX; + /* we need to decide how to handle this */ } - if (val > (double) UINT64_MAX) { + if ((uint64_t) val > UINT64_MAX) { return UINT64_MAX; } - return (uint64_t) val; + memcpy(&tmp, &val, sizeof(double)); + return (uint64_t) (tmp); } static inline double cmt_math_uint64_to_d64(uint64_t val) { - return (double) val; + double tmp; + + memcpy(&tmp, &val, sizeof(uint64_t)); + return tmp; } #endif