From 8bf425957b253d0ab2e4902d57340b19b7436698 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 13 Jan 2020 16:51:58 -0500 Subject: fix regressions double implicit casting return ptr --- src/softfloat.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/softfloat.hpp') diff --git a/src/softfloat.hpp b/src/softfloat.hpp index 4b227e9d7c..a1173690b5 100644 --- a/src/softfloat.hpp +++ b/src/softfloat.hpp @@ -12,4 +12,21 @@ extern "C" { #include "softfloat.h" } +static inline float16_t zig_double_to_f16(double x) { + float64_t y; + static_assert(sizeof(x) == sizeof(y), ""); + memcpy(&y, &x, sizeof(x)); + return f64_to_f16(y); +} + + +// Return value is safe to coerce to float even when |x| is NaN or Infinity. +static inline double zig_f16_to_double(float16_t x) { + float64_t y = f16_to_f64(x); + double z; + static_assert(sizeof(y) == sizeof(z), ""); + memcpy(&z, &y, sizeof(y)); + return z; +} + #endif -- cgit v1.2.3