complex.inc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* -*-c-*-*/
  2. #include "ffitest.h"
  3. #include <complex.h>
  4. static _Complex T_C_TYPE f_complex(_Complex T_C_TYPE c, int x, int *py)
  5. {
  6. c = -(2 * creal (c)) + (cimag (c) + 1)* I;
  7. *py += x;
  8. return c;
  9. }
  10. int main (void)
  11. {
  12. ffi_cif cif;
  13. ffi_type *args[MAX_ARGS];
  14. void *values[MAX_ARGS];
  15. _Complex T_C_TYPE tc_arg;
  16. _Complex T_C_TYPE tc_result;
  17. int tc_int_arg_x;
  18. int tc_y;
  19. int *tc_ptr_arg_y = &tc_y;
  20. args[0] = &T_FFI_TYPE;
  21. args[1] = &ffi_type_sint;
  22. args[2] = &ffi_type_pointer;
  23. values[0] = &tc_arg;
  24. values[1] = &tc_int_arg_x;
  25. values[2] = &tc_ptr_arg_y;
  26. /* Initialize the cif */
  27. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
  28. &T_FFI_TYPE, args) == FFI_OK);
  29. tc_arg = 1 + 7 * I;
  30. tc_int_arg_x = 1234;
  31. tc_y = 9876;
  32. ffi_call(&cif, FFI_FN(f_complex), &tc_result, values);
  33. printf ("%f,%fi %f,%fi, x %d 1234, y %d 11110\n",
  34. T_CONV creal (tc_result), T_CONV cimag (tc_result),
  35. T_CONV creal (2.0), T_CONV creal (8.0), tc_int_arg_x, tc_y);
  36. CHECK (creal (tc_result) == -2);
  37. CHECK (cimag (tc_result) == 8);
  38. CHECK (tc_int_arg_x == 1234);
  39. CHECK (*tc_ptr_arg_y == 11110);
  40. exit(0);
  41. }