Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

float3.c
Go to the documentation of this file.
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 static double floating_1(float a, double b, long double c)
13 {
14 return (double) a + b + (double) c;
15 }
16
17 static double floating_2(long double a, double b, float c)
18 {
19 return (double) a + b + (double) c;
20 }
21
22 int main (void)
23 {
24 ffi_cif cif;
25 ffi_type *args[MAX_ARGS];
26 void *values[MAX_ARGS];
27 double rd;
28
29 float f;
30 double d;
31 long double ld;
32
33 args[0] = &ffi_type_float;
34 values[0] = &f;
35 args[1] = &ffi_type_double;
36 values[1] = &d;
37 args[2] = &ffi_type_longdouble;
38 values[2] = &ld;
39
40 /* Initialize the cif */
41 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
42 &ffi_type_double, args) == FFI_OK);
43
44 f = 3.14159;
45 d = (double)1.0/(double)3.0;
46 ld = 2.71828182846L;
47
48 floating_1 (f, d, ld);
49
50 ffi_call(&cif, FFI_FN(floating_1), &rd, values);
51
52 CHECK(rd - floating_1(f, d, ld) < DBL_EPSILON);
53
54 args[0] = &ffi_type_longdouble;
55 values[0] = &ld;
56 args[1] = &ffi_type_double;
57 values[1] = &d;
58 args[2] = &ffi_type_float;
59 values[2] = &f;
60
61 /* Initialize the cif */
62 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
63 &ffi_type_double, args) == FFI_OK);
64
65 floating_2 (ld, d, f);
66
67 ffi_call(&cif, FFI_FN(floating_2), &rd, values);
68
69 CHECK(rd - floating_2(ld, d, f) < DBL_EPSILON);
70
71 exit (0);
72 }
DBL_EPSILON
#define DBL_EPSILON
Definition: numeric.c:61
large_tag::b
unsigned b
Definition: cls_struct_va1.c:20
large_tag::c
unsigned c
Definition: cls_struct_va1.c:21
exit
void exit(int __status) __attribute__((__noreturn__))
ffitest.h
double
double
Definition: rb_mjit_min_header-2.7.0.h:5923
main
int main(void)
Definition: float3.c:22
CHECK
#define CHECK(sub)
Definition: compile.c:448
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
f
#define f
large_tag::d
unsigned d
Definition: cls_struct_va1.c:22
ffi_prep_cif
ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, ffi_type *rtype, ffi_type **atypes)
Definition: prep_cif.c:226
MAX_ARGS
#define MAX_ARGS
Definition: function.c:15
ffi_call
void ffi_call(ffi_cif *cif, void(*fn)(void), void *rvalue, void **avalue)
Definition: ffi.c:813
large_tag::a
unsigned a
Definition: cls_struct_va1.c:19