float2.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Area: ffi_call
  2. Purpose: Check return value long 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. static long double ldblit(float f)
  11. {
  12. return (long double) (((long double) f)/ (long double) 3.0);
  13. }
  14. int main (void)
  15. {
  16. ffi_cif cif;
  17. ffi_type *args[MAX_ARGS];
  18. void *values[MAX_ARGS];
  19. float f;
  20. long double ld;
  21. long double original;
  22. args[0] = &ffi_type_float;
  23. values[0] = &f;
  24. /* Initialize the cif */
  25. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
  26. &ffi_type_longdouble, args) == FFI_OK);
  27. f = 3.14159;
  28. #if defined(__sun) && defined(__GNUC__)
  29. /* long double support under SunOS/gcc is pretty much non-existent.
  30. You'll get the odd bus error in library routines like printf() */
  31. #else
  32. printf ("%Lf\n", ldblit(f));
  33. #endif
  34. ld = 666;
  35. ffi_call(&cif, FFI_FN(ldblit), &ld, values);
  36. #if defined(__sun) && defined(__GNUC__)
  37. /* long double support under SunOS/gcc is pretty much non-existent.
  38. You'll get the odd bus error in library routines like printf() */
  39. #else
  40. printf ("%Lf, %Lf, %Lf, %Lf\n", ld, ldblit(f), ld - ldblit(f), LDBL_EPSILON);
  41. #endif
  42. /* These are not always the same!! Check for a reasonable delta */
  43. original = ldblit(f);
  44. if (((ld > original) ? (ld - original) : (original - ld)) < LDBL_EPSILON)
  45. puts("long double return value tests ok!");
  46. else
  47. CHECK(0);
  48. exit(0);
  49. }