[PATCH] D146188: [Clang][DOC] Add documentation in for __builtin_flt_rounds and __builtin_set_flt_rounds

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 28 12:57:47 PDT 2023


rjmccall added inline comments.


================
Comment at: clang/docs/LanguageExtensions.rst:3272
+3  - toward negative infinity
+4  - to nearest, ties away from zero
+The effect of passing some other value to ``__builtin_flt_rounds`` is
----------------
I suspect this won't end up being formatted as a list; you should do something like:

```
- ``0`` - toward zero
- ``1`` - to nearest, ties to even
...
```


================
Comment at: clang/docs/UsersManual.rst:1388
+by calling the `fesetround` function.
+
 Clang provides a number of ways to control floating point behavior, including
----------------
This isn't quite the right place for this.  Please put this new subsection after the described flags but before the "A note about..." subsections.

This file is RST, so you need to use double-backticks to format text in monospace.

This paragraph is just talking about the default mode which restricts access to the floating-point environment; let's add some text after it on how to get out of that default mode:

```
C provides two pragmas to allow code to dynamically modify the floating point environment:

- ``#pragma STDC FENV_ACCESS ON`` allows dynamic changes to the entire floating point environment.

- ``#pragma STDC FENV_ROUND FE_DYNAMIC`` allows dynamic changes to just the floating point rounding mode.  This may be more optimizable than ``FENV_ACCESS ON`` because the compiler can still ignore the possibility of floating-point exceptions by default.

Both of these can be used either at the start of a block scope, in which case they cover all code in that scope (unless they're turned off in a child scope), or at the top level in a file, in which case they cover all subsequent function bodies until they're turned off.  Note that it is undefined behavior to enter code that is *not* covered by one of these pragmas from code that *is* covered by one of these pragmas unless the floating point environment has been restored to its default state.  See the C standard for more information about these pragmas.

The command line option ``-frounding-math`` behaves as if the translation unit began with ``#pragma STDC FENV_ROUND FE_DYNAMIC``.  The command line option ``-ffp-model=strict`` behaves as if the translation unit began with ``#pragma STDC FENV_ACCESS ON``.

Code that just wants to use a specific rounding mode for specific floating point operations can avoid most of the hazards of the dynamic floating point environment by using ``#pragma STDC FENV_ROUND`` with a value other than ``FE_DYNAMIC``.
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146188/new/

https://reviews.llvm.org/D146188



More information about the cfe-commits mailing list