From 9622ede2e24067a09380c63da8d5007ec1f03dc4 Mon Sep 17 00:00:00 2001 From: Anatoly Trosinenko Date: Fri, 14 Nov 2014 13:18:04 +0300 Subject: [PATCH] Fix floating point number comparisons in testsuite/libffi.call/float[123].c. Rewrite the checks for approximate equality of floating point return values to be in the form "fabs(a - b) < EPS" instead of just "a - b < EPS". --- testsuite/libffi.call/float1.c | 4 +++- testsuite/libffi.call/float2.c | 4 +++- testsuite/libffi.call/float3.c | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/testsuite/libffi.call/float1.c b/testsuite/libffi.call/float1.c index 991d059f..c48493c6 100644 --- a/testsuite/libffi.call/float1.c +++ b/testsuite/libffi.call/float1.c @@ -8,6 +8,8 @@ #include "ffitest.h" #include "float.h" +#include + typedef union { double d; @@ -47,7 +49,7 @@ int main (void) /* These are not always the same!! Check for a reasonable delta */ - CHECK(result[0].d - dblit(f) < DBL_EPSILON); + CHECK(fabs(result[0].d - dblit(f)) < DBL_EPSILON); /* Check the canary. */ for (i = 0; i < sizeof (double); ++i) diff --git a/testsuite/libffi.call/float2.c b/testsuite/libffi.call/float2.c index 419c2bde..20a8c402 100644 --- a/testsuite/libffi.call/float2.c +++ b/testsuite/libffi.call/float2.c @@ -8,6 +8,8 @@ #include "ffitest.h" #include "float.h" +#include + static long double ldblit(float f) { return (long double) (((long double) f)/ (long double) 3.0); @@ -47,7 +49,7 @@ int main (void) #endif /* These are not always the same!! Check for a reasonable delta */ - if (ld - ldblit(f) < LDBL_EPSILON) + if (fabsl(ld - ldblit(f)) < LDBL_EPSILON) puts("long double return value tests ok!"); else CHECK(0); diff --git a/testsuite/libffi.call/float3.c b/testsuite/libffi.call/float3.c index 76bd5f28..bab3206a 100644 --- a/testsuite/libffi.call/float3.c +++ b/testsuite/libffi.call/float3.c @@ -9,6 +9,8 @@ #include "ffitest.h" #include "float.h" +#include + static double floating_1(float a, double b, long double c) { return (double) a + b + (double) c; @@ -49,7 +51,7 @@ int main (void) ffi_call(&cif, FFI_FN(floating_1), &rd, values); - CHECK(rd - floating_1(f, d, ld) < DBL_EPSILON); + CHECK(fabs(rd - floating_1(f, d, ld)) < DBL_EPSILON); args[0] = &ffi_type_longdouble; values[0] = &ld; @@ -66,7 +68,7 @@ int main (void) ffi_call(&cif, FFI_FN(floating_2), &rd, values); - CHECK(rd - floating_2(ld, d, f) < DBL_EPSILON); + CHECK(fabs(rd - floating_2(ld, d, f)) < DBL_EPSILON); exit (0); }