1 1.1 joerg //===-- floatdisf_test.c - Test __floatdisf -------------------------------===// 2 1.1 joerg // 3 1.1 joerg // The LLVM Compiler Infrastructure 4 1.1 joerg // 5 1.1 joerg // This file is dual licensed under the MIT and the University of Illinois Open 6 1.1 joerg // Source Licenses. See LICENSE.TXT for details. 7 1.1 joerg // 8 1.1 joerg //===----------------------------------------------------------------------===// 9 1.1 joerg // 10 1.1 joerg // This file tests __floatdisf for the compiler_rt library. 11 1.1 joerg // 12 1.1 joerg //===----------------------------------------------------------------------===// 13 1.1 joerg 14 1.1 joerg #include "int_lib.h" 15 1.1 joerg #include <float.h> 16 1.1 joerg #include <stdio.h> 17 1.1 joerg 18 1.1 joerg // Returns: convert a to a float, rounding toward even. 19 1.1 joerg 20 1.1 joerg // Assumption: float is a IEEE 32 bit floating point type 21 1.1 joerg // di_int is a 64 bit integral type 22 1.1 joerg 23 1.1 joerg // seee eeee emmm mmmm mmmm mmmm mmmm mmmm 24 1.1 joerg 25 1.1 joerg float __floatdisf(di_int a); 26 1.1 joerg 27 1.1 joerg int test__floatdisf(di_int a, float expected) 28 1.1 joerg { 29 1.1 joerg float x = __floatdisf(a); 30 1.1 joerg if (x != expected) 31 1.1 joerg printf("error in __floatdisf(%llX) = %a, expected %a\n", 32 1.1 joerg a, x, expected); 33 1.1 joerg return x != expected; 34 1.1 joerg } 35 1.1 joerg 36 1.1 joerg char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0}; 37 1.1 joerg char assumption_2[sizeof(di_int)*CHAR_BIT == 64] = {0}; 38 1.1 joerg char assumption_3[sizeof(float)*CHAR_BIT == 32] = {0}; 39 1.1 joerg 40 1.1 joerg int main() 41 1.1 joerg { 42 1.1 joerg if (test__floatdisf(0, 0.0F)) 43 1.1 joerg return 1; 44 1.1 joerg 45 1.1 joerg if (test__floatdisf(1, 1.0F)) 46 1.1 joerg return 1; 47 1.1 joerg if (test__floatdisf(2, 2.0F)) 48 1.1 joerg return 1; 49 1.1 joerg if (test__floatdisf(-1, -1.0F)) 50 1.1 joerg return 1; 51 1.1 joerg if (test__floatdisf(-2, -2.0F)) 52 1.1 joerg return 1; 53 1.1 joerg 54 1.1 joerg if (test__floatdisf(0x7FFFFF8000000000LL, 0x1.FFFFFEp+62F)) 55 1.1 joerg return 1; 56 1.1 joerg if (test__floatdisf(0x7FFFFF0000000000LL, 0x1.FFFFFCp+62F)) 57 1.1 joerg return 1; 58 1.1 joerg 59 1.1 joerg if (test__floatdisf(0x8000008000000000LL, -0x1.FFFFFEp+62F)) 60 1.1 joerg return 1; 61 1.1 joerg if (test__floatdisf(0x8000010000000000LL, -0x1.FFFFFCp+62F)) 62 1.1 joerg return 1; 63 1.1 joerg 64 1.1 joerg if (test__floatdisf(0x8000000000000000LL, -0x1.000000p+63F)) 65 1.1 joerg return 1; 66 1.1 joerg if (test__floatdisf(0x8000000000000001LL, -0x1.000000p+63F)) 67 1.1 joerg return 1; 68 1.1 joerg 69 1.1 joerg if (test__floatdisf(0x0007FB72E8000000LL, 0x1.FEDCBAp+50F)) 70 1.1 joerg return 1; 71 1.1 joerg 72 1.1 joerg if (test__floatdisf(0x0007FB72EA000000LL, 0x1.FEDCBAp+50F)) 73 1.1 joerg return 1; 74 1.1 joerg if (test__floatdisf(0x0007FB72EB000000LL, 0x1.FEDCBAp+50F)) 75 1.1 joerg return 1; 76 1.1 joerg if (test__floatdisf(0x0007FB72EBFFFFFFLL, 0x1.FEDCBAp+50F)) 77 1.1 joerg return 1; 78 1.1 joerg if (test__floatdisf(0x0007FB72EC000000LL, 0x1.FEDCBCp+50F)) 79 1.1 joerg return 1; 80 1.1 joerg if (test__floatdisf(0x0007FB72E8000001LL, 0x1.FEDCBAp+50F)) 81 1.1 joerg return 1; 82 1.1 joerg 83 1.1 joerg if (test__floatdisf(0x0007FB72E6000000LL, 0x1.FEDCBAp+50F)) 84 1.1 joerg return 1; 85 1.1 joerg if (test__floatdisf(0x0007FB72E7000000LL, 0x1.FEDCBAp+50F)) 86 1.1 joerg return 1; 87 1.1 joerg if (test__floatdisf(0x0007FB72E7FFFFFFLL, 0x1.FEDCBAp+50F)) 88 1.1 joerg return 1; 89 1.1 joerg if (test__floatdisf(0x0007FB72E4000001LL, 0x1.FEDCBAp+50F)) 90 1.1 joerg return 1; 91 1.1 joerg if (test__floatdisf(0x0007FB72E4000000LL, 0x1.FEDCB8p+50F)) 92 1.1 joerg return 1; 93 1.1 joerg 94 1.1 joerg return 0; 95 1.1 joerg } 96