Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

float.c
Go to the documentation of this file.
1 /* Area: ffi_call
2 Purpose: Check return value float.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
6
7 /* { dg-do run } */
8
9 #include "ffitest.h"
10
11 static int floating(int a, float b, double c, long double d)
12 {
13 int i;
14
15 i = (int) ((float)a/b + ((float)c/(float)d));
16
17 return i;
18 }
19
20 int main (void)
21 {
22 ffi_cif cif;
23 ffi_type *args[MAX_ARGS];
24 void *values[MAX_ARGS];
25 ffi_arg rint;
26
27 float f;
28 signed int si1;
29 double d;
30 long double ld;
31
32 args[0] = &ffi_type_sint;
33 values[0] = &si1;
34 args[1] = &ffi_type_float;
35 values[1] = &f;
36 args[2] = &ffi_type_double;
37 values[2] = &d;
38 args[3] = &ffi_type_longdouble;
39 values[3] = &ld;
40
41 /* Initialize the cif */
42 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
43 &ffi_type_sint, args) == FFI_OK);
44
45 si1 = 6;
46 f = 3.14159;
47 d = (double)1.0/(double)3.0;
48 ld = 2.71828182846L;
49
50 floating (si1, f, d, ld);
51
52 ffi_call(&cif, FFI_FN(floating), &rint, values);
53
54 printf ("%d vs %d\n", (int)rint, floating (si1, f, d, ld));
55
56 CHECK((int)rint == floating(si1, f, d, ld));
57
58 exit (0);
59 }
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
large_tag::b
unsigned b
Definition: cls_struct_va1.c:20
main
int main(void)
Definition: float.c:20
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
large_tag::c
unsigned c
Definition: cls_struct_va1.c:21
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
exit
void exit(int __status) __attribute__((__noreturn__))
ffitest.h
double
double
Definition: rb_mjit_min_header-2.7.0.h:5923
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
CHECK
#define CHECK(sub)
Definition: compile.c:448
rint
double rint(double)
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