1 /* Area:	ffi_call
2    Purpose:	Check float arguments with different orders.
3    Limitations:	none.
4    PR:		none.
5    Originator:	From the original ffitest.c  */
6 
7 /* { dg-do run } */
8 
9 #include "ffitest.h"
10 #include "float.h"
11 
12 #include <math.h>
13 
floating_1(float a,double b,long double c)14 static double floating_1(float a, double b, long double c)
15 {
16   return (double) a + b + (double) c;
17 }
18 
floating_2(long double a,double b,float c)19 static double floating_2(long double a, double b, float c)
20 {
21   return (double) a + b + (double) c;
22 }
23 
main(void)24 int main (void)
25 {
26   ffi_cif cif;
27   ffi_type *args[MAX_ARGS];
28   void *values[MAX_ARGS];
29   double rd;
30 
31   float f;
32   double d;
33   long double ld;
34 
35   args[0] = &ffi_type_float;
36   values[0] = &f;
37   args[1] = &ffi_type_double;
38   values[1] = &d;
39   args[2] = &ffi_type_longdouble;
40   values[2] = &ld;
41 
42   /* Initialize the cif */
43   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
44 		     &ffi_type_double, args) == FFI_OK);
45 
46   f = 3.14159;
47   d = (double)1.0/(double)3.0;
48   ld = 2.71828182846L;
49 
50   floating_1 (f, d, ld);
51 
52   ffi_call(&cif, FFI_FN(floating_1), &rd, values);
53 
54   CHECK(fabs(rd - floating_1(f, d, ld)) < DBL_EPSILON);
55 
56   args[0] = &ffi_type_longdouble;
57   values[0] = &ld;
58   args[1] = &ffi_type_double;
59   values[1] = &d;
60   args[2] = &ffi_type_float;
61   values[2] = &f;
62 
63   /* Initialize the cif */
64   CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
65 		     &ffi_type_double, args) == FFI_OK);
66 
67   floating_2 (ld, d, f);
68 
69   ffi_call(&cif, FFI_FN(floating_2), &rd, values);
70 
71   CHECK(fabs(rd - floating_2(ld, d, f)) < DBL_EPSILON);
72 
73   exit (0);
74 }
75