Home | History | Annotate | Download | only in Unit
      1 //===--------------- subtf3_test.c - Test __subtf3 ------------------------===//
      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 __subtf3 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 // Returns: a - b
     21 COMPILER_RT_ABI long double __subtf3(long double a, long double b);
     22 
     23 int test__subtf3(long double a, long double b,
     24                  uint64_t expectedHi, uint64_t expectedLo)
     25 {
     26     long double x = __subtf3(a, b);
     27     int ret = compareResultLD(x, expectedHi, expectedLo);
     28 
     29     if (ret){
     30         printf("error in test__subtf3(%.20Lf, %.20Lf) = %.20Lf, "
     31                "expected %.20Lf\n", a, b, x,
     32                fromRep128(expectedHi, expectedLo));
     33     }
     34     return ret;
     35 }
     36 
     37 char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
     38 
     39 #endif
     40 
     41 int main()
     42 {
     43 #if __LDBL_MANT_DIG__ == 113
     44     // qNaN - any = qNaN
     45     if (test__subtf3(makeQNaN128(),
     46                      0x1.23456789abcdefp+5L,
     47                      UINT64_C(0x7fff800000000000),
     48                      UINT64_C(0x0)))
     49         return 1;
     50     // NaN - any = NaN
     51     if (test__subtf3(makeNaN128(UINT64_C(0x800030000000)),
     52                      0x1.23456789abcdefp+5L,
     53                      UINT64_C(0x7fff800000000000),
     54                      UINT64_C(0x0)))
     55         return 1;
     56     // inf - any = inf
     57     if (test__subtf3(makeInf128(),
     58                      0x1.23456789abcdefp+5L,
     59                      UINT64_C(0x7fff000000000000),
     60                      UINT64_C(0x0)))
     61         return 1;
     62     // any - any
     63     if (test__subtf3(0x1.234567829a3bcdef5678ade36734p+5L,
     64                      0x1.ee9d7c52354a6936ab8d7654321fp-1L,
     65                      UINT64_C(0x40041b8af1915166),
     66                      UINT64_C(0xa44a7bca780a166c)))
     67         return 1;
     68 
     69 #else
     70     printf("skipped\n");
     71 
     72 #endif
     73     return 0;
     74 }
     75