1 //===-- fixunssfsi_test.c - Test __fixunssfsi -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests __fixunssfsi for the compiler_rt library.
12 //===----------------------------------------------------------------------===//
17 // Returns: convert a to a unsigned int, rounding toward zero.
18 // Negative values all become zero.
20 // Assumption: float is a IEEE 32 bit floating point type
21 // su_int is a 32 bit integral type
22 // value in float is representable in su_int or is negative
23 // (no range checking performed)
25 // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
27 su_int
__fixunssfsi(float a
);
29 int test__fixunssfsi(float a
, su_int expected
)
31 su_int x
= __fixunssfsi(a
);
33 printf("error in __fixunssfsi(%A) = %X, expected %X\n", a
, x
, expected
);
37 char assumption_2
[sizeof(su_int
)*CHAR_BIT
== 32] = {0};
38 char assumption_3
[sizeof(float)*CHAR_BIT
== 32] = {0};
42 if (test__fixunssfsi(0.0F
, 0))
45 if (test__fixunssfsi(0.5F
, 0))
47 if (test__fixunssfsi(0.99F
, 0))
49 if (test__fixunssfsi(1.0F
, 1))
51 if (test__fixunssfsi(1.5F
, 1))
53 if (test__fixunssfsi(1.99F
, 1))
55 if (test__fixunssfsi(2.0F
, 2))
57 if (test__fixunssfsi(2.01F
, 2))
59 if (test__fixunssfsi(-0.5F
, 0))
61 if (test__fixunssfsi(-0.99F
, 0))
64 if (test__fixunssfsi(-1.0F
, 0)) // libgcc ignores "returns 0 for negative input" spec
66 if (test__fixunssfsi(-1.5F
, 0))
68 if (test__fixunssfsi(-1.99F
, 0))
70 if (test__fixunssfsi(-2.0F
, 0))
72 if (test__fixunssfsi(-2.01F
, 0))
76 if (test__fixunssfsi(0x1.000000p
+31F
, 0x80000000))
78 if (test__fixunssfsi(0x1.FFFFFEp
+31F
, 0xFFFFFF00))
80 if (test__fixunssfsi(0x1.FFFFFEp
+30F
, 0x7FFFFF80))
82 if (test__fixunssfsi(0x1.FFFFFCp
+30F
, 0x7FFFFF00))
86 if (test__fixunssfsi(-0x1.FFFFFEp
+30F
, 0))
88 if (test__fixunssfsi(-0x1.FFFFFCp
+30F
, 0))