]> git.ipfire.org Git - thirdparty/gcc.git/blob - libffi/testsuite/libffi.call/float2.c
libffi: Sync with libffi 3.4.2
[thirdparty/gcc.git] / libffi / testsuite / libffi.call / float2.c
1 /* Area: ffi_call
2 Purpose: Check return value long double.
3 Limitations: none.
4 PR: none.
5 Originator: From the original ffitest.c */
6 /* { dg-do run } */
7
8 #include "ffitest.h"
9 #include "float.h"
10
11 #include <math.h>
12
13 static long double ldblit(float f)
14 {
15 return (long double) (((long double) f)/ (long double) 3.0);
16 }
17
18 int main (void)
19 {
20 ffi_cif cif;
21 ffi_type *args[MAX_ARGS];
22 void *values[MAX_ARGS];
23 float f;
24 long double ld;
25 long double original;
26
27 args[0] = &ffi_type_float;
28 values[0] = &f;
29
30 /* Initialize the cif */
31 CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
32 &ffi_type_longdouble, args) == FFI_OK);
33
34 f = 3.14159;
35
36 #if defined(__sun) && defined(__GNUC__)
37 /* long double support under SunOS/gcc is pretty much non-existent.
38 You'll get the odd bus error in library routines like printf() */
39 #else
40 printf ("%Lf\n", ldblit(f));
41 #endif
42
43 ld = 666;
44 ffi_call(&cif, FFI_FN(ldblit), &ld, values);
45
46 #if defined(__sun) && defined(__GNUC__)
47 /* long double support under SunOS/gcc is pretty much non-existent.
48 You'll get the odd bus error in library routines like printf() */
49 #else
50 printf ("%Lf, %Lf, %Lf, %Lf\n", ld, ldblit(f), ld - ldblit(f), LDBL_EPSILON);
51 #endif
52
53 /* These are not always the same!! Check for a reasonable delta */
54 original = ldblit(f);
55 if (((ld > original) ? (ld - original) : (original - ld)) < LDBL_EPSILON)
56 puts("long double return value tests ok!");
57 else
58 CHECK(0);
59
60 exit(0);
61 }