Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / tcg / i386 / test-i386-snan-convert.c
blobed6d535ce20ec2aabd4b8f30ac2b002fbe2a5b87
1 /* Test conversions of signaling NaNs to and from long double. */
3 #include <stdint.h>
4 #include <stdio.h>
6 volatile float f_res;
7 volatile double d_res;
8 volatile long double ld_res;
10 volatile float f_snan = __builtin_nansf("");
11 volatile double d_snan = __builtin_nans("");
12 volatile long double ld_snan = __builtin_nansl("");
14 int issignaling_f(float x)
16 union { float f; uint32_t u; } u = { .f = x };
17 return (u.u & 0x7fffffff) > 0x7f800000 && (u.u & 0x400000) == 0;
20 int issignaling_d(double x)
22 union { double d; uint64_t u; } u = { .d = x };
23 return (((u.u & UINT64_C(0x7fffffffffffffff)) >
24 UINT64_C(0x7ff0000000000000)) &&
25 (u.u & UINT64_C(0x8000000000000)) == 0);
28 int issignaling_ld(long double x)
30 union {
31 long double ld;
32 struct { uint64_t sig; uint16_t sign_exp; } s;
33 } u = { .ld = x };
34 return ((u.s.sign_exp & 0x7fff) == 0x7fff &&
35 (u.s.sig >> 63) != 0 &&
36 (u.s.sig & UINT64_C(0x4000000000000000)) == 0);
39 int main(void)
41 int ret = 0;
42 ld_res = f_snan;
43 if (issignaling_ld(ld_res)) {
44 printf("FAIL: float -> long double\n");
45 ret = 1;
47 ld_res = d_snan;
48 if (issignaling_ld(ld_res)) {
49 printf("FAIL: double -> long double\n");
50 ret = 1;
52 f_res = ld_snan;
53 if (issignaling_d(f_res)) {
54 printf("FAIL: long double -> float\n");
55 ret = 1;
57 d_res = ld_snan;
58 if (issignaling_d(d_res)) {
59 printf("FAIL: long double -> double\n");
60 ret = 1;
62 return ret;