many_mixed.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Area: ffi_call
  2. Purpose: Check return value double, with many arguments
  3. Limitations: none.
  4. PR: none.
  5. Originator: From the original ffitest.c */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. #include <stdlib.h>
  9. #include <float.h>
  10. #include <math.h>
  11. static double many(double f1,
  12. double f2,
  13. long int i1,
  14. double f3,
  15. double f4,
  16. long int i2,
  17. double f5,
  18. double f6,
  19. long int i3,
  20. double f7,
  21. double f8,
  22. long int i4,
  23. double f9,
  24. double f10,
  25. long int i5,
  26. double f11,
  27. double f12,
  28. long int i6,
  29. double f13)
  30. {
  31. return ((double) (i1 + i2 + i3 + i4 + i5 + i6) + (f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12) * f13);
  32. }
  33. int main (void)
  34. {
  35. ffi_cif cif;
  36. ffi_type *args[19];
  37. void *values[19];
  38. double fa[19];
  39. long int la[19];
  40. double f, ff;
  41. int i;
  42. for (i = 0; i < 19; i++)
  43. {
  44. if( (i - 2) % 3 == 0) {
  45. args[i] = &ffi_type_slong;
  46. la[i] = (long int) i;
  47. values[i] = &la[i];
  48. }
  49. else {
  50. args[i] = &ffi_type_double;
  51. fa[i] = (double) i;
  52. values[i] = &fa[i];
  53. }
  54. }
  55. /* Initialize the cif */
  56. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 19,
  57. &ffi_type_double, args) == FFI_OK);
  58. ffi_call(&cif, FFI_FN(many), &f, values);
  59. ff = many(fa[0], fa[1], la[2],
  60. fa[3], fa[4], la[5],
  61. fa[6], fa[7], la[8],
  62. fa[9], fa[10], la[11],
  63. fa[12], fa[13], la[14],
  64. fa[15], fa[16], la[17],
  65. fa[18]);
  66. if (fabs(f - ff) < FLT_EPSILON)
  67. exit(0);
  68. else
  69. abort();
  70. }