authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-01 18:25:43+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-01 14:30:31-07:00
log2957433b25373dccc336492f6817a1cefadb945c
treebdef4c40bfc6b1e325e49cac310c8efee0119085
parentd530e7f9c7e19b2c9d9117c3120cd75855f4023b

stage1: Fix comptime comparison of NaNs


2 files changed, 15 insertions(+), 2 deletions(-)

src/stage1/ir.cpp+2-2
......@@ -10953,13 +10953,13 @@ static bool float_is_nan(ZigValue *op) {
1095310953 } else if (op->type->id == ZigTypeIdFloat) {
1095410954 switch (op->type->data.floating.bit_count) {
1095510955 case 16:
10956 return f16_isSignalingNaN(op->data.x_f16);
10956 return zig_f16_isNaN(op->data.x_f16);
1095710957 case 32:
1095810958 return op->data.x_f32 != op->data.x_f32;
1095910959 case 64:
1096010960 return op->data.x_f64 != op->data.x_f64;
1096110961 case 128:
10962 return f128M_isSignalingNaN(&op->data.x_f128);
10962 return zig_f128_isNaN(&op->data.x_f128);
1096310963 default:
1096410964 zig_unreachable();
1096510965 }
src/stage1/softfloat.hpp+13
......@@ -29,4 +29,17 @@ static inline double zig_f16_to_double(float16_t x) {
2929 return z;
3030}
3131
32static inline bool zig_f16_isNaN(float16_t a) {
33 union { uint16_t ui; float16_t f; } uA;
34 uA.f = a;
35 return 0x7C00 < (uA.ui & 0x7FFF);
36}
37
38static inline bool zig_f128_isNaN(float128_t *aPtr) {
39 uint64_t absA64 = aPtr->v[1] & UINT64_C(0x7FFFFFFFFFFFFFFF);
40 return
41 (UINT64_C(0x7FFF000000000000) < absA64)
42 || ((absA64 == UINT64_C(0x7FFF000000000000)) && aPtr->v[0]);
43}
44
3245#endif