Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Exception handling



On 2013-08-12 14:01:18 -0400, Michel Hack wrote:
> Exactly what I was going to say.  On the other hand, it must also be the
> case that actual Interval Arithmetic is allowed to leave the 754 state
> in an unpredictable state.  I think it would be onerous to require that
> each interval operation must save and restore the 754 status flags.

IMHO, this is an API problem, thus out of the scope of the standard.

Indeed, *any* library function on the platform is potentially
concerned by altering the 754 status flags and being affected
by traps set on some exceptions.

The standard could recommend some behavior, but the final choice won't
be based on it. For instance, the C standard says in 7.6p3:

  Certain programming conventions support the intended model of use
  for the floating-point environment:206)

  - a function call does not alter its caller's floating-point control
    modes, clear its caller's floating-point status flags, nor depend
    on the state of its caller's floating-point status flags unless
    the function is so documented;

  - a function call is assumed to require default floating-point
    control modes, unless its documentation promises otherwise;

  - a function call is assumed to have the potential for raising
    floating-point exceptions, unless its documentation promises
    otherwise.

These are conventions for C. Other languages and the system itself
(for interoperability between languages) may have similar or other
conventions...

> It should however preserve the 754 rounding direction of the current block
> of execution -- though it might be useful to have a compile-time pragma
> that provides the programmer some control.  Such a mechanism already
> exists for C, based on <fenv.h> and #pragma STDC FENV_ACCESS on/off, to
> declare whether the program depends on maintaining IEEE 754 flags, or not.

The STDC FENV_ACCESS pragma isn't there to declare whether the program
depends on maintaining IEEE 754 flags, but:

  The FENV_ACCESS pragma provides a means to inform the implementation
  when a program might access the floating-point environment to test
  floating-point status flags or run under non-default floating-point
  control modes.

The only goal is to prevent some unsafe optimizations from being used.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)