stage1: Fix comptime comparison of NaNs

master
LemonBoy 2020-11-01 18:25:43 +01:00 committed by Andrew Kelley
parent d530e7f9c7
commit 2957433b25
2 changed files with 15 additions and 2 deletions

View File

@ -10953,13 +10953,13 @@ static bool float_is_nan(ZigValue *op) {
} else if (op->type->id == ZigTypeIdFloat) {
switch (op->type->data.floating.bit_count) {
case 16:
return f16_isSignalingNaN(op->data.x_f16);
return zig_f16_isNaN(op->data.x_f16);
case 32:
return op->data.x_f32 != op->data.x_f32;
case 64:
return op->data.x_f64 != op->data.x_f64;
case 128:
return f128M_isSignalingNaN(&op->data.x_f128);
return zig_f128_isNaN(&op->data.x_f128);
default:
zig_unreachable();
}

View File

@ -29,4 +29,17 @@ static inline double zig_f16_to_double(float16_t x) {
return z;
}
static inline bool zig_f16_isNaN(float16_t a) {
union { uint16_t ui; float16_t f; } uA;
uA.f = a;
return 0x7C00 < (uA.ui & 0x7FFF);
}
static inline bool zig_f128_isNaN(float128_t *aPtr) {
uint64_t absA64 = aPtr->v[1] & UINT64_C(0x7FFFFFFFFFFFFFFF);
return
(UINT64_C(0x7FFF000000000000) < absA64)
|| ((absA64 == UINT64_C(0x7FFF000000000000)) && aPtr->v[0]);
}
#endif