diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-01-29 23:33:12 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-01-29 23:33:12 -0500 |
| commit | a95dce15ae4bd95cfd2266da51ba860cc6524a1b (patch) | |
| tree | e761ecb74f37ff699d2e1f09d122811b101826e4 /src/softfloat.hpp | |
| parent | 800ead2810fa573a7e94979e707a14d4e066ef77 (diff) | |
| parent | 7ebc624a15c5a01d6bee8eaf9c7487b30ed1904c (diff) | |
| download | zig-a95dce15ae4bd95cfd2266da51ba860cc6524a1b.tar.gz zig-a95dce15ae4bd95cfd2266da51ba860cc6524a1b.zip | |
Merge remote-tracking branch 'origin/master' into llvm10
Diffstat (limited to 'src/softfloat.hpp')
| -rw-r--r-- | src/softfloat.hpp | 17 |
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 |
