aboutsummaryrefslogtreecommitdiff
path: root/src/softfloat.hpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-01-13 16:51:58 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-01-16 21:58:52 -0500
commit8bf425957b253d0ab2e4902d57340b19b7436698 (patch)
tree3a62b6c16a64313195c5b01154bf8ee631aec97f /src/softfloat.hpp
parente48157c3cb817ff1551f74fc1da9f420e38ccbd5 (diff)
downloadzig-8bf425957b253d0ab2e4902d57340b19b7436698.tar.gz
zig-8bf425957b253d0ab2e4902d57340b19b7436698.zip
fix regressions double implicit casting return ptr
Diffstat (limited to 'src/softfloat.hpp')
-rw-r--r--src/softfloat.hpp17
1 files changed, 17 insertions, 0 deletions
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