float3.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /* { dg-do run } */
  7. #include "ffitest.h"
  8. #include "float.h"
  9. #include <math.h>
  10. static double floating_1(float a, double b, long double c)
  11. {
  12. return (double) a + b + (double) c;
  13. }
  14. static double floating_2(long double a, double b, float c)
  15. {
  16. return (double) a + b + (double) c;
  17. }
  18. int main (void)
  19. {
  20. ffi_cif cif;
  21. ffi_type *args[MAX_ARGS];
  22. void *values[MAX_ARGS];
  23. double rd;
  24. float f;
  25. double d;
  26. long double ld;
  27. args[0] = &ffi_type_float;
  28. values[0] = &f;
  29. args[1] = &ffi_type_double;
  30. values[1] = &d;
  31. args[2] = &ffi_type_longdouble;
  32. values[2] = &ld;
  33. /* Initialize the cif */
  34. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
  35. &ffi_type_double, args) == FFI_OK);
  36. f = 3.14159;
  37. d = (double)1.0/(double)3.0;
  38. ld = 2.71828182846L;
  39. floating_1 (f, d, ld);
  40. ffi_call(&cif, FFI_FN(floating_1), &rd, values);
  41. CHECK(fabs(rd - floating_1(f, d, ld)) < DBL_EPSILON);
  42. args[0] = &ffi_type_longdouble;
  43. values[0] = &ld;
  44. args[1] = &ffi_type_double;
  45. values[1] = &d;
  46. args[2] = &ffi_type_float;
  47. values[2] = &f;
  48. /* Initialize the cif */
  49. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
  50. &ffi_type_double, args) == FFI_OK);
  51. floating_2 (ld, d, f);
  52. ffi_call(&cif, FFI_FN(floating_2), &rd, values);
  53. CHECK(fabs(rd - floating_2(ld, d, f)) < DBL_EPSILON);
  54. exit (0);
  55. }