Skip to content

fix inconsistent handling of floating point exceptions on android port

username-removed-1342825 requested to merge spaghettisalat/ecl:develop into develop

I recently found inconsistencies with regards to floating point exceptions on the android port of ECL. The problem is that when compiled to C-code, many operations dealing with infinities such as assignment of an infinite floating point throw an overflow exception, while bytecode compiled code does not. On an x86 PC, both operations work without signaling an exception. The C-compiler outputs code of the form:

   double v1;
   v1 = INFINITY;
   si_Xmake_constant(VV[0], ecl_make_double_float(v1));

ecl_make_double_float immediately checks for NaN or infinities:

cl_object
ecl_make_double_float(double f)
{
  cl_object x;

  DO_DETECT_FPE(f);

DO_DETECT_FPE is defined as follows on an ARM processor:

# define DO_DETECT_FPE(f) do {                                  \
    unlikely_if (isnan(f)) ecl_deliver_fpe(FE_INVALID);         \
    unlikely_if (!isfinite(f)) ecl_deliver_fpe(FE_OVERFLOW);    \
  } while (0)

But this check should only be done, when there was actually a computation beforehand. With this patch, the C-compiler and the FFI interface now use new functions, which don't check for FPEs. In all other cases, the checks remain.

PS: I hope it is OK, if I report errors, for which I already have a fix, with a merge request instead of creating a new issue.

Merge request reports