float.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Area: ffi_call
  2. Purpose: Check return value float.
  3. Limitations: none.
  4. PR: none.
  5. Originator: From the original ffitest.c */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. static int floating(int a, float b, double c, long double d)
  9. {
  10. int i;
  11. i = (int) ((float)a/b + ((float)c/(float)d));
  12. return i;
  13. }
  14. int main (void)
  15. {
  16. ffi_cif cif;
  17. ffi_type *args[MAX_ARGS];
  18. void *values[MAX_ARGS];
  19. ffi_arg rint;
  20. float f;
  21. signed int si1;
  22. double d;
  23. long double ld;
  24. args[0] = &ffi_type_sint;
  25. values[0] = &si1;
  26. args[1] = &ffi_type_float;
  27. values[1] = &f;
  28. args[2] = &ffi_type_double;
  29. values[2] = &d;
  30. args[3] = &ffi_type_longdouble;
  31. values[3] = &ld;
  32. /* Initialize the cif */
  33. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
  34. &ffi_type_sint, args) == FFI_OK);
  35. si1 = 6;
  36. f = 3.14159;
  37. d = (double)1.0/(double)3.0;
  38. ld = 2.71828182846L;
  39. floating (si1, f, d, ld);
  40. ffi_call(&cif, FFI_FN(floating), &rint, values);
  41. printf ("%d vs %d\n", (int)rint, floating (si1, f, d, ld));
  42. CHECK((int)rint == floating(si1, f, d, ld));
  43. exit (0);
  44. }