1// RUN: %clang_builtins %s %librt -o %t && %run %t 2 3//===--------------- truncdfhf2_test.c - Test __truncdfhf2 ----------------===// 4// 5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6// See https://llvm.org/LICENSE.txt for license information. 7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8// 9//===----------------------------------------------------------------------===// 10// 11// This file tests __truncdfhf2 for the compiler_rt library. 12// 13//===----------------------------------------------------------------------===// 14 15#include <stdio.h> 16 17#include "fp_test.h" 18 19uint16_t __truncdfhf2(double a); 20 21int test__truncdfhf2(double a, uint16_t expected) 22{ 23 uint16_t x = __truncdfhf2(a); 24 int ret = compareResultH(x, expected); 25 26 if (ret){ 27 printf("error in test__truncdfhf2(%f) = %#.4x, " 28 "expected %#.4x\n", a, x, fromRep16(expected)); 29 } 30 return ret; 31} 32 33char assumption_1[sizeof(__fp16) * CHAR_BIT == 16] = {0}; 34 35int main() 36{ 37 // qNaN 38 if (test__truncdfhf2(makeQNaN64(), 39 UINT16_C(0x7e00))) 40 return 1; 41 // NaN 42 if (test__truncdfhf2(makeNaN64(UINT64_C(0x8000)), 43 UINT16_C(0x7e00))) 44 return 1; 45 // inf 46 if (test__truncdfhf2(makeInf64(), 47 UINT16_C(0x7c00))) 48 return 1; 49 if (test__truncdfhf2(-makeInf64(), 50 UINT16_C(0xfc00))) 51 return 1; 52 // zero 53 if (test__truncdfhf2(0.0, UINT16_C(0x0))) 54 return 1; 55 if (test__truncdfhf2(-0.0, UINT16_C(0x8000))) 56 return 1; 57 58 if (test__truncdfhf2(3.1415926535, 59 UINT16_C(0x4248))) 60 return 1; 61 if (test__truncdfhf2(-3.1415926535, 62 UINT16_C(0xc248))) 63 return 1; 64 if (test__truncdfhf2(0x1.987124876876324p+1000, 65 UINT16_C(0x7c00))) 66 return 1; 67 if (test__truncdfhf2(0x1.987124876876324p+12, 68 UINT16_C(0x6e62))) 69 return 1; 70 if (test__truncdfhf2(0x1.0p+0, 71 UINT16_C(0x3c00))) 72 return 1; 73 if (test__truncdfhf2(0x1.0p-14, 74 UINT16_C(0x0400))) 75 return 1; 76 // denormal 77 if (test__truncdfhf2(0x1.0p-20, 78 UINT16_C(0x0010))) 79 return 1; 80 if (test__truncdfhf2(0x1.0p-24, 81 UINT16_C(0x0001))) 82 return 1; 83 if (test__truncdfhf2(-0x1.0p-24, 84 UINT16_C(0x8001))) 85 return 1; 86 if (test__truncdfhf2(0x1.5p-25, 87 UINT16_C(0x0001))) 88 return 1; 89 // and back to zero 90 if (test__truncdfhf2(0x1.0p-25, 91 UINT16_C(0x0000))) 92 return 1; 93 if (test__truncdfhf2(-0x1.0p-25, 94 UINT16_C(0x8000))) 95 return 1; 96 // max (precise) 97 if (test__truncdfhf2(65504.0, 98 UINT16_C(0x7bff))) 99 return 1; 100 // max (rounded) 101 if (test__truncdfhf2(65519.0, 102 UINT16_C(0x7bff))) 103 return 1; 104 // max (to +inf) 105 if (test__truncdfhf2(65520.0, 106 UINT16_C(0x7c00))) 107 return 1; 108 if (test__truncdfhf2(-65520.0, 109 UINT16_C(0xfc00))) 110 return 1; 111 if (test__truncdfhf2(65536.0, 112 UINT16_C(0x7c00))) 113 return 1; 114 return 0; 115} 116