[Cfp-interest 2703] Re: Floating point rounding modes

Vincent Lefevre vincent at vinc17.net
Wed Feb 22 03:21:22 PST 2023


On 2023-02-22 11:52:08 +0100, Paul Zimmermann wrote:
>        Vincent,
> 
> > A question: The code is designed to work in all rounding modes.
> > But couldn't it be made simpler/faster if the rounding mode is
> > known to be rounding to nearest (assuming that the processor
> > has static rounding modes)?
> 
> maybe it would save one bit in the error analysis.
> However, if all computations are done with rounding to nearest,
> how would you round the final double-double approximation hi+lo
> towards say +Infinity?

I think that there are 2 non-exclusive solutions if static
rounding modes are used:

1. Have different functions, one for each rounding mode,
   e.g. crsin_n, crsin_d, crsin_u, crsin_z.

2. Have an additional argument (like MPFR).

> > But how is the code used currently? With GCC, it is known that
> > changing the rounding mode is not supported. I don't know about
> > the other compilers. Another question is: Will future processors
> > support static rounding modes, knowing that the current situation
> > is rather bad (changing the rounding mode is very slow, and
> > dynamic rounding modes also make optimization more difficult
> > and partly impossible)?
> 
> as I said previously on this list, the user can use the code as follows,
> following the ISO C standard:
> 
>    double x, y;
>    fesetround (FE_TOWARDZERO);
>    y = sin (x); /* or y = cr_sin(x) */

This is not portable and incorrect, as FE_TOWARDZERO might not be
available or fesetround may fail. The ISO C standard C99 to C17 says:

  Each of the macros

    FE_DOWNWARD
    FE_TONEAREST
    FE_TOWARDZERO
    FE_UPWARD

  is defined if and only if the implementation supports getting
  and setting the represented rounding direction by means of the
  fegetround and fesetround functions.

So, if a processor only has static rounding, these macros will not
normally be defined, possibly except FE_TONEAREST. This was the case
with old ARM processors, which had static rounding.

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


More information about the Cfp-interest mailing list