xref: /minix3/sys/external/bsd/compiler_rt/dist/test/Unit/fixsfdi_test.c (revision 4684ddb6aab0b36791c8099bc705d6140b3d05d0)
1*4684ddb6SLionel Sambuc //===-- fixsfdi_test.c - Test __fixsfdi -----------------------------------===//
2*4684ddb6SLionel Sambuc //
3*4684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
4*4684ddb6SLionel Sambuc //
5*4684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
6*4684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
7*4684ddb6SLionel Sambuc //
8*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
9*4684ddb6SLionel Sambuc //
10*4684ddb6SLionel Sambuc // This file tests __fixsfdi for the compiler_rt library.
11*4684ddb6SLionel Sambuc //
12*4684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
13*4684ddb6SLionel Sambuc 
14*4684ddb6SLionel Sambuc #include "int_lib.h"
15*4684ddb6SLionel Sambuc #include <stdio.h>
16*4684ddb6SLionel Sambuc 
17*4684ddb6SLionel Sambuc // Returns: convert a to a signed long long, rounding toward zero.
18*4684ddb6SLionel Sambuc 
19*4684ddb6SLionel Sambuc // Assumption: float is a IEEE 32 bit floating point type
20*4684ddb6SLionel Sambuc //             su_int is a 32 bit integral type
21*4684ddb6SLionel Sambuc //             value in float is representable in di_int (no range checking performed)
22*4684ddb6SLionel Sambuc 
23*4684ddb6SLionel Sambuc // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
24*4684ddb6SLionel Sambuc 
25*4684ddb6SLionel Sambuc di_int __fixsfdi(float a);
26*4684ddb6SLionel Sambuc 
test__fixsfdi(float a,di_int expected)27*4684ddb6SLionel Sambuc int test__fixsfdi(float a, di_int expected)
28*4684ddb6SLionel Sambuc {
29*4684ddb6SLionel Sambuc     di_int x = __fixsfdi(a);
30*4684ddb6SLionel Sambuc     if (x != expected)
31*4684ddb6SLionel Sambuc         printf("error in __fixsfdi(%A) = %llX, expected %llX\n", a, x, expected);
32*4684ddb6SLionel Sambuc     return x != expected;
33*4684ddb6SLionel Sambuc }
34*4684ddb6SLionel Sambuc 
35*4684ddb6SLionel Sambuc char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
36*4684ddb6SLionel Sambuc char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
37*4684ddb6SLionel Sambuc char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0};
38*4684ddb6SLionel Sambuc 
main()39*4684ddb6SLionel Sambuc int main()
40*4684ddb6SLionel Sambuc {
41*4684ddb6SLionel Sambuc     if (test__fixsfdi(0.0F, 0))
42*4684ddb6SLionel Sambuc         return 1;
43*4684ddb6SLionel Sambuc 
44*4684ddb6SLionel Sambuc     if (test__fixsfdi(0.5F, 0))
45*4684ddb6SLionel Sambuc         return 1;
46*4684ddb6SLionel Sambuc     if (test__fixsfdi(0.99F, 0))
47*4684ddb6SLionel Sambuc         return 1;
48*4684ddb6SLionel Sambuc     if (test__fixsfdi(1.0F, 1))
49*4684ddb6SLionel Sambuc         return 1;
50*4684ddb6SLionel Sambuc     if (test__fixsfdi(1.5F, 1))
51*4684ddb6SLionel Sambuc         return 1;
52*4684ddb6SLionel Sambuc     if (test__fixsfdi(1.99F, 1))
53*4684ddb6SLionel Sambuc         return 1;
54*4684ddb6SLionel Sambuc     if (test__fixsfdi(2.0F, 2))
55*4684ddb6SLionel Sambuc         return 1;
56*4684ddb6SLionel Sambuc     if (test__fixsfdi(2.01F, 2))
57*4684ddb6SLionel Sambuc         return 1;
58*4684ddb6SLionel Sambuc     if (test__fixsfdi(-0.5F, 0))
59*4684ddb6SLionel Sambuc         return 1;
60*4684ddb6SLionel Sambuc     if (test__fixsfdi(-0.99F, 0))
61*4684ddb6SLionel Sambuc         return 1;
62*4684ddb6SLionel Sambuc     if (test__fixsfdi(-1.0F, -1))
63*4684ddb6SLionel Sambuc         return 1;
64*4684ddb6SLionel Sambuc     if (test__fixsfdi(-1.5F, -1))
65*4684ddb6SLionel Sambuc         return 1;
66*4684ddb6SLionel Sambuc     if (test__fixsfdi(-1.99F, -1))
67*4684ddb6SLionel Sambuc         return 1;
68*4684ddb6SLionel Sambuc     if (test__fixsfdi(-2.0F, -2))
69*4684ddb6SLionel Sambuc         return 1;
70*4684ddb6SLionel Sambuc     if (test__fixsfdi(-2.01F, -2))
71*4684ddb6SLionel Sambuc         return 1;
72*4684ddb6SLionel Sambuc 
73*4684ddb6SLionel Sambuc     if (test__fixsfdi(0x1.FFFFFEp+62F, 0x7FFFFF8000000000LL))
74*4684ddb6SLionel Sambuc         return 1;
75*4684ddb6SLionel Sambuc     if (test__fixsfdi(0x1.FFFFFCp+62F, 0x7FFFFF0000000000LL))
76*4684ddb6SLionel Sambuc         return 1;
77*4684ddb6SLionel Sambuc 
78*4684ddb6SLionel Sambuc     if (test__fixsfdi(-0x1.FFFFFEp+62F, 0x8000008000000000LL))
79*4684ddb6SLionel Sambuc         return 1;
80*4684ddb6SLionel Sambuc     if (test__fixsfdi(-0x1.FFFFFCp+62F, 0x8000010000000000LL))
81*4684ddb6SLionel Sambuc         return 1;
82*4684ddb6SLionel Sambuc 
83*4684ddb6SLionel Sambuc    return 0;
84*4684ddb6SLionel Sambuc }
85