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

Vincent Lefevre vincent at vinc17.net
Fri Jan 27 07:09:51 PST 2023


On 2023-01-05 09:47:50 +0100, Paul Zimmermann wrote:
> as far as I know, the answer is no. Indeed something like
> double x = 0.1downward would be nice. The workaround is to use
> strtod() assuming it is correctly rounded and evaluated at compile time
> (is it?). Setting x = 0.1 after fesetround (FE_UPWARD) does not seem to
> work (I just tried with gcc).

0.1 is what is called a "constant" (Section 6.4.4) and #8 says
"Floating constants are converted to internal format as if at
translation-time."

6.4.4 alone does not seem to require rounding to nearest, but as
#8 also says "All floating constants of the same source form shall
convert to the same internal format with the same value.", if you
have:

  fesetround (FE_UPWARD);
  x = 0.1;
  fesetround (FE_DOWNWARD);
  y = 0.1;

then x and y must have the same value, even though the rounding mode
is known at translation-time (i.e. the compiler is not allowed to
honor a known rounding mode in such a case).

-- 
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