tsan: deflake tests
[blocksruntime.git] / test / Unit / fixdfdi_test.c
blobd08afe3a53368661d8e0de6daa42f3c2f42edf65
1 //===-- fixdfdi_test.c - Test __fixdfdi -----------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file tests __fixdfdi for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
14 #include "int_lib.h"
15 #include <stdio.h>
17 // Returns: convert a to a signed long long, rounding toward zero.
19 // Assumption: double is a IEEE 64 bit floating point type
20 // su_int is a 32 bit integral type
21 // value in double is representable in di_int (no range checking performed)
23 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
25 di_int __fixdfdi(double a);
27 int test__fixdfdi(double a, di_int expected)
29 di_int x = __fixdfdi(a);
30 if (x != expected)
31 printf("error in __fixdfdi(%A) = %llX, expected %llX\n", a, x, expected);
32 return x != expected;
35 char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
36 char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
37 char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0};
39 int main()
41 if (test__fixdfdi(0.0, 0))
42 return 1;
44 if (test__fixdfdi(0.5, 0))
45 return 1;
46 if (test__fixdfdi(0.99, 0))
47 return 1;
48 if (test__fixdfdi(1.0, 1))
49 return 1;
50 if (test__fixdfdi(1.5, 1))
51 return 1;
52 if (test__fixdfdi(1.99, 1))
53 return 1;
54 if (test__fixdfdi(2.0, 2))
55 return 1;
56 if (test__fixdfdi(2.01, 2))
57 return 1;
58 if (test__fixdfdi(-0.5, 0))
59 return 1;
60 if (test__fixdfdi(-0.99, 0))
61 return 1;
62 if (test__fixdfdi(-1.0, -1))
63 return 1;
64 if (test__fixdfdi(-1.5, -1))
65 return 1;
66 if (test__fixdfdi(-1.99, -1))
67 return 1;
68 if (test__fixdfdi(-2.0, -2))
69 return 1;
70 if (test__fixdfdi(-2.01, -2))
71 return 1;
73 if (test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
74 return 1;
75 if (test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
76 return 1;
78 if (test__fixdfdi(-0x1.FFFFFEp+62, 0x8000008000000000LL))
79 return 1;
80 if (test__fixdfdi(-0x1.FFFFFCp+62, 0x8000010000000000LL))
81 return 1;
83 if (test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
84 return 1;
85 if (test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
86 return 1;
88 if (test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, 0x8000000000000400LL))
89 return 1;
90 if (test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, 0x8000000000000800LL))
91 return 1;
93 return 0;