float1.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Area: ffi_call
  2. Purpose: Check return value double.
  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. typedef union
  11. {
  12. double d;
  13. unsigned char c[sizeof (double)];
  14. } value_type;
  15. #define CANARY 0xba
  16. static double dblit(float f)
  17. {
  18. return f/3.0;
  19. }
  20. int main (void)
  21. {
  22. ffi_cif cif;
  23. ffi_type *args[MAX_ARGS];
  24. void *values[MAX_ARGS];
  25. float f;
  26. value_type result[2];
  27. unsigned int i;
  28. args[0] = &ffi_type_float;
  29. values[0] = &f;
  30. /* Initialize the cif */
  31. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  32. &ffi_type_double, args) == FFI_OK);
  33. f = 3.14159;
  34. /* Put a canary in the return array. This is a regression test for
  35. a buffer overrun. */
  36. memset(result[1].c, CANARY, sizeof (double));
  37. ffi_call(&cif, FFI_FN(dblit), &result[0].d, values);
  38. /* These are not always the same!! Check for a reasonable delta */
  39. CHECK(fabs(result[0].d - dblit(f)) < DBL_EPSILON);
  40. /* Check the canary. */
  41. for (i = 0; i < sizeof (double); ++i)
  42. CHECK(result[1].c[i] == CANARY);
  43. exit(0);
  44. }