bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: math error reporting


From: Bastien ROUCARIES
Subject: Re: math error reporting
Date: Mon, 7 Nov 2011 11:10:26 +0000

On Sun, Nov 6, 2011 at 8:36 PM, Bruno Haible <address@hidden> wrote:
> Hi,
>
> Considering how gnulib-implemented <math.h> functions should do their
> error reporting, I ran a test program to see how the various systems
> implement math errors.
>
> ============================================================================
> #include <errno.h>
> #include <math.h>
> #include <stdio.h>
> #ifndef NO_FENV
> #include <fenv.h>
> #endif
> int main()
> {
>  double result;
>  errno = 0;
> #ifndef NO_FENV
>  fprintf (stderr, "before: %s\n",
>           fetestexcept (FE_INVALID) ? "invalid" : "");
> #endif
>  result = sqrt (-1.0);
> #ifndef NO_FENV
>  fprintf (stderr, "%g, after: %s, errno=%d\n", result,
>           fetestexcept (FE_INVALID) ? "invalid" : "", errno);
> #else
>  fprintf (stderr, "%g, after: errno=%d\n", result, errno);
> #endif
>  return 0;
> }
> ============================================================================
>
> The result:
>
>   glibc 2.11:   NaN, fenv bit, errno
>   MacOS X 10.5: NaN, fenv bit          math_errhandling 
> (always=MATH_ERREXCEPT)
>   FreeBSD 6.4:  NaN, fenv bit          math_errhandling 
> (always=MATH_ERREXCEPT)
>   OpenBSD 4.9:  NaN
>   NetBSD 5.1:   NaN,           errno
>   AIX 7.1:      NaN, fenv bit, errno   math_errhandling (always=MATH_ERRNO)
>   HP-UX 11.31:  NaN, fenv bit, errno
>   IRIX 6.5:     NaN
>   OSF/1 5.1:    0,             errno   (<fenv.h> incomplete)
>   Solaris 10:   NaN, fenv bit, errno   math_errhandling 
> (always=MATH_ERREXCEPT)
>   Cygwin 1.7.9: NaN,           errno
>   mingw:        NaN, fenv bit, errno
>   MSVC 9:       NaN,           errno
>
> * All platforms except OSF/1 return a NaN value.
>
> * All platform that have a complete <fenv.h> (OSF/1 has an incomplete
>  <fenv.h>) set the FE_INVALID bit in sqrt(-1).
>
> * Some platforms set errno, some don't.
>
> * math_errhandling is missing on many platforms. On those platforms where
>  it is defined, it is useless, though:
>    - All platforms that have math_errhandling also have <fenv.h>, therefore
>      you don't need to consider math_errhandling if you want to know whether
>      to set a floating-point exception bit.
>    - Some of the platforms that set errno have a math_errhandling that
>      includes MATH_ERRNO (AIX), some don't (Solaris).
>
> I am inclined to do the following in gnulib:
>
> 1) Provide a complete <fenv.h> on all platforms. glibc contains the code
>   for the CPUs which are missing in the table above (x86, x86_64, sparc,
>   mips, alpha).
>
> 2) Define math_errhandling everywhere, and override it on AIX and Solaris.
>
> How does that sound? (It's a lot of work, I know.)
>
> Is it likely that the IRIX, OSF/1, or MSVC compilers are implementing the
> math operators and functions in a way does not set the floating-point
> exception bits correctly (thus making <fenv.h> useless)?

msvc is compliant but a the microsoft taste
https://www.securecoding.cert.org/confluence/display/seccode/FLP03-C.+Detect+and+handle+floating+point+errors
and
http://msdn.microsoft.com/en-us/library/te2k2f2t%28v=vs.80%29.aspx

Bastien

> Bruno
> --
> In memoriam Louis Philippe d'Orléans 
> <http://en.wikipedia.org/wiki/Louis_Philippe_II,_Duke_of_Orléans>
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]