85 lines · c
1// RUN: %clang_builtins %s %librt -o %t && %run %t2// REQUIRES: librt_has_fixdfdi3 4#include "int_lib.h"5#include <stdio.h>6 7// Returns: convert a to a signed long long, rounding toward zero.8 9// Assumption: double is a IEEE 64 bit floating point type 10// su_int is a 32 bit integral type11// value in double is representable in di_int (no range checking performed)12 13// seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm14 15COMPILER_RT_ABI di_int __fixdfdi(double a);16 17int test__fixdfdi(double a, di_int expected)18{19 di_int x = __fixdfdi(a);20 if (x != expected)21 printf("error in __fixdfdi(%A) = %llX, expected %llX\n", a, x, expected);22 return x != expected;23}24 25char assumption_1[sizeof(di_int) == 2*sizeof(si_int)] = {0};26char assumption_2[sizeof(su_int)*CHAR_BIT == 32] = {0};27char assumption_3[sizeof(double)*CHAR_BIT == 64] = {0};28 29int main()30{31 if (test__fixdfdi(0.0, 0))32 return 1;33 34 if (test__fixdfdi(0.5, 0))35 return 1;36 if (test__fixdfdi(0.99, 0))37 return 1;38 if (test__fixdfdi(1.0, 1))39 return 1;40 if (test__fixdfdi(1.5, 1))41 return 1;42 if (test__fixdfdi(1.99, 1))43 return 1;44 if (test__fixdfdi(2.0, 2))45 return 1;46 if (test__fixdfdi(2.01, 2))47 return 1;48 if (test__fixdfdi(-0.5, 0))49 return 1;50 if (test__fixdfdi(-0.99, 0))51 return 1;52 if (test__fixdfdi(-1.0, -1))53 return 1;54 if (test__fixdfdi(-1.5, -1))55 return 1;56 if (test__fixdfdi(-1.99, -1))57 return 1;58 if (test__fixdfdi(-2.0, -2))59 return 1;60 if (test__fixdfdi(-2.01, -2))61 return 1;62 63 if (test__fixdfdi(0x1.FFFFFEp+62, 0x7FFFFF8000000000LL))64 return 1;65 if (test__fixdfdi(0x1.FFFFFCp+62, 0x7FFFFF0000000000LL))66 return 1;67 68 if (test__fixdfdi(-0x1.FFFFFEp+62, 0x8000008000000000LL))69 return 1;70 if (test__fixdfdi(-0x1.FFFFFCp+62, 0x8000010000000000LL))71 return 1;72 73 if (test__fixdfdi(0x1.FFFFFFFFFFFFFp+62, 0x7FFFFFFFFFFFFC00LL))74 return 1;75 if (test__fixdfdi(0x1.FFFFFFFFFFFFEp+62, 0x7FFFFFFFFFFFF800LL))76 return 1;77 78 if (test__fixdfdi(-0x1.FFFFFFFFFFFFFp+62, 0x8000000000000400LL))79 return 1;80 if (test__fixdfdi(-0x1.FFFFFFFFFFFFEp+62, 0x8000000000000800LL))81 return 1;82 83 return 0;84}85