Home | History | Annotate | Download | only in Unit
      1 //===--------------- trunctfsf2_test.c - Test __trunctfsf2 ----------------===//
      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 __trunctfsf2 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include <stdio.h>
     15 
     16 #if __LDBL_MANT_DIG__ == 113
     17 
     18 #include "fp_test.h"
     19 
     20 float __trunctfsf2(long double a);
     21 
     22 int test__trunctfsf2(long double a, uint32_t expected)
     23 {
     24     float x = __trunctfsf2(a);
     25     int ret = compareResultF(x, expected);
     26 
     27     if (ret){
     28         printf("error in test__trunctfsf2(%.20Lf) = %f, "
     29                "expected %f\n", a, x, fromRep32(expected));
     30     }
     31     return ret;
     32 }
     33 
     34 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
     35 
     36 #endif
     37 
     38 int main()
     39 {
     40 #if __LDBL_MANT_DIG__ == 113
     41     // qNaN
     42     if (test__trunctfsf2(makeQNaN128(),
     43                          UINT32_C(0x7fc00000)))
     44         return 1;
     45     // NaN
     46     if (test__trunctfsf2(makeNaN128(UINT64_C(0x810000000000)),
     47                          UINT32_C(0x7fc08000)))
     48         return 1;
     49     // inf
     50     if (test__trunctfsf2(makeInf128(),
     51                          UINT32_C(0x7f800000)))
     52         return 1;
     53     // zero
     54     if (test__trunctfsf2(0.0L, UINT32_C(0x0)))
     55         return 1;
     56 
     57     if (test__trunctfsf2(0x1.23a2abb4a2ddee355f36789abcdep+5L,
     58                          UINT32_C(0x4211d156)))
     59         return 1;
     60     if (test__trunctfsf2(0x1.e3d3c45bd3abfd98b76a54cc321fp-9L,
     61                          UINT32_C(0x3b71e9e2)))
     62         return 1;
     63     if (test__trunctfsf2(0x1.234eebb5faa678f4488693abcdefp+4534L,
     64                          UINT32_C(0x7f800000)))
     65         return 1;
     66     if (test__trunctfsf2(0x1.edcba9bb8c76a5a43dd21f334634p-435L,
     67                          UINT32_C(0x0)))
     68         return 1;
     69 
     70 #else
     71     printf("skipped\n");
     72 
     73 #endif
     74     return 0;
     75 }
     76