blob: 43ac0f8aaa3c3d0d569be0ace044365700b2f2c3 [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- fixxfdi_test.c - Test __fixxfdi -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Daniel Dunbarb3a69012009-06-26 16:47:03 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file tests __fixxfdi for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014#include "int_lib.h"
15#include <stdio.h>
16
Nick Kledzik3ea82872009-09-11 19:09:36 +000017
18#if HAS_80_BIT_LONG_DOUBLE
Daniel Dunbarb3a69012009-06-26 16:47:03 +000019// Returns: convert a to a signed long long, rounding toward zero.
20
21// Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
22// su_int is a 32 bit integral type
23// value in long double is representable in di_int (no range checking performed)
24
25// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
26// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
27
28di_int __fixxfdi(long double a);
29
30int test__fixxfdi(long double a, di_int expected)
31{
32 di_int x = __fixxfdi(a);
33 if (x != expected)
34 printf("error in __fixxfdi(%LA) = %llX, expected %llX\n",
35 a, x, expected);
36 return x != expected;
37}
38
39char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};
40char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};
41char assumption_3[sizeof(long double)*CHAR_BIT == 128] = {0};
Daniel Dunbarb3a69012009-06-26 16:47:03 +000042#endif
43
44int main()
45{
Nick Kledzik3ea82872009-09-11 19:09:36 +000046#if HAS_80_BIT_LONG_DOUBLE
Daniel Dunbarb3a69012009-06-26 16:47:03 +000047 if (test__fixxfdi(0.0, 0))
48 return 1;
49
50 if (test__fixxfdi(0.5, 0))
51 return 1;
52 if (test__fixxfdi(0.99, 0))
53 return 1;
54 if (test__fixxfdi(1.0, 1))
55 return 1;
56 if (test__fixxfdi(1.5, 1))
57 return 1;
58 if (test__fixxfdi(1.99, 1))
59 return 1;
60 if (test__fixxfdi(2.0, 2))
61 return 1;
62 if (test__fixxfdi(2.01, 2))
63 return 1;
64 if (test__fixxfdi(-0.5, 0))
65 return 1;
66 if (test__fixxfdi(-0.99, 0))
67 return 1;
68 if (test__fixxfdi(-1.0, -1))
69 return 1;
70 if (test__fixxfdi(-1.5, -1))
71 return 1;
72 if (test__fixxfdi(-1.99, -1))
73 return 1;
74 if (test__fixxfdi(-2.0, -2))
75 return 1;
76 if (test__fixxfdi(-2.01, -2))
77 return 1;
78
79 if (test__fixxfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))
80 return 1;
81 if (test__fixxfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))
82 return 1;
83
84 if (test__fixxfdi(-0x1.FFFFFEp+62, 0x8000008000000000LL))
85 return 1;
86 if (test__fixxfdi(-0x1.FFFFFCp+62, 0x8000010000000000LL))
87 return 1;
88
89 if (test__fixxfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))
90 return 1;
91 if (test__fixxfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))
92 return 1;
93
94 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFp+62, 0x8000000000000400LL))
95 return 1;
96 if (test__fixxfdi(-0x1.FFFFFFFFFFFFEp+62, 0x8000000000000800LL))
97 return 1;
98
99 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFFCp+62L, 0x7FFFFFFFFFFFFFFFLL))
100 return 1;
101 if (test__fixxfdi(0x1.FFFFFFFFFFFFFFF8p+62L, 0x7FFFFFFFFFFFFFFELL))
102 return 1;
103
104 if (test__fixxfdi(-0x1.0000000000000000p+63L, 0x8000000000000000LL))
105 return 1;
106 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFFCp+62L, 0x8000000000000001LL))
107 return 1;
108 if (test__fixxfdi(-0x1.FFFFFFFFFFFFFFF8p+62L, 0x8000000000000002LL))
109 return 1;
110
Joerg Sonnenberger74828152011-05-29 21:43:29 +0000111#else
112 printf("skipped\n");
Daniel Dunbarb3a69012009-06-26 16:47:03 +0000113#endif
114 return 0;
115}