Home | History | Annotate | Download | only in Unit
      1 //===--------------- addtf3_test.c - Test __addtf3 ------------------------===//
      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 __addtf3 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 
     17 #if __LDBL_MANT_DIG__ == 113
     18 
     19 #include "fp_test.h"
     20 
     21 // Returns: a + b
     22 COMPILER_RT_ABI long double __addtf3(long double a, long double b);
     23 
     24 int test__addtf3(long double a, long double b,
     25                  uint64_t expectedHi, uint64_t expectedLo)
     26 {
     27     long double x = __addtf3(a, b);
     28     int ret = compareResultLD(x, expectedHi, expectedLo);
     29 
     30     if (ret){
     31         printf("error in test__addtf3(%.20Lf, %.20Lf) = %.20Lf, "
     32                "expected %.20Lf\n", a, b, x,
     33                fromRep128(expectedHi, expectedLo));
     34     }
     35 
     36     return ret;
     37 }
     38 
     39 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
     40 
     41 #endif
     42 
     43 int main()
     44 {
     45 #if __LDBL_MANT_DIG__ == 113
     46     // qNaN + any = qNaN
     47     if (test__addtf3(makeQNaN128(),
     48                      0x1.23456789abcdefp+5L,
     49                      UINT64_C(0x7fff800000000000),
     50                      UINT64_C(0x0)))
     51         return 1;
     52     // NaN + any = NaN
     53     if (test__addtf3(makeNaN128(UINT64_C(0x800030000000)),
     54                      0x1.23456789abcdefp+5L,
     55                      UINT64_C(0x7fff800000000000),
     56                      UINT64_C(0x0)))
     57         return 1;
     58     // inf + inf = inf
     59     if (test__addtf3(makeInf128(),
     60                      makeInf128(),
     61                      UINT64_C(0x7fff000000000000),
     62                      UINT64_C(0x0)))
     63         return 1;
     64     // inf + any = inf
     65     if (test__addtf3(makeInf128(),
     66                      0x1.2335653452436234723489432abcdefp+5L,
     67                      UINT64_C(0x7fff000000000000),
     68                      UINT64_C(0x0)))
     69         return 1;
     70     // any + any
     71     if (test__addtf3(0x1.23456734245345543849abcdefp+5L,
     72                      0x1.edcba52449872455634654321fp-1L,
     73                      UINT64_C(0x40042afc95c8b579),
     74                      UINT64_C(0x61e58dd6c51eb77c)))
     75         return 1;
     76 
     77 #else
     78     printf("skipped\n");
     79 
     80 #endif
     81     return 0;
     82 }
     83