[Vm-dev] ffi-test-main.c fails on FreeBSD

Eliot Miranda eliot.miranda at gmail.com
Thu Nov 19 17:44:12 UTC 2009

On Thu, Nov 19, 2009 at 9:29 AM, John M McIntosh <
johnmci at smalltalkconsulting.com> wrote:

> > define FLT_EPSILON as something like 1e-20 and rewrite the check as
> CHECK(fabs(f - ff) < FLT_EPSILON)?
> >
> > In math epsilon is a small value tending towards zero.  The intent here
> is to check that you get back something close to ff without assuming that
> the floating-point arithmetic involved in many is exact enough to return ff.
> Ok, the implication then for testing is that
> ffiPushSingleFloat
> ffiReturnFloatValue
> modify the floating point value slightly, if that is acceptable
> then you need to epsilon test.

No.  Look at the body of many:

static float many(float f1, float f2, float f3, float f4, float f5, float
f6, float f7, float f8, float f9, float f10, float f11, float f12, float
f13, float f14, float f15)
  DPRINTF(("%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n",
     (double)f1, (double)f2, (double)f3, (double)f4, (double)f5,
     (double)f6, (double)f7, (double)f8, (double)f9, (double)f10,
     (double)f11, (double)f12, (double)f13, (double)f14, (double)f15));
  return ((f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12+f13/f14) * f15);

There's lots of scope for floating-point rounding errors here, so the
epsilon test is required.  There's no implication that any float marshalling
code alters the values involved.  That would be a huge bug.

> also GCC seems to define
> #define FLT_EPSILON 1.19209290e-07F
> across all flavours of CPUs and float word lengths.
> perhaps via "float.h"
> --
> ===========================================================================
> John M. McIntosh <johnmci at smalltalkconsulting.com>   Twitter:
>  squeaker68882
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ===========================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20091119/b941b948/attachment.htm

More information about the Vm-dev mailing list