Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 798aee2

Browse files
authored
Merge pull request numpy#11073 from mattip/doc-11036
DOC: expand reasoning behind npy_*floatstatus_barrer()
2 parents cc8cef9 + 1e00cc5 commit 798aee2

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

doc/source/reference/c-api.coremath.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,19 @@ Those can be useful for precise floating point comparison.
183183
* NPY_FPE_UNDERFLOW
184184
* NPY_FPE_INVALID
185185
186+
Note that :c:func:`npy_get_floatstatus_barrier` is preferable as it prevents
187+
agressive compiler optimizations reordering the call relative to
188+
the code setting the status, which could lead to incorrect results.
189+
186190
.. versionadded:: 1.9.0
187191
188192
.. c:function:: int npy_get_floatstatus_barrier(char*)
189193
190194
Get floating point status. A pointer to a local variable is passed in to
191-
prevent aggresive compiler optimizations from reodering this function call.
195+
prevent aggresive compiler optimizations from reodering this function call
196+
relative to the code setting the status, which could lead to incorrect
197+
results.
198+
192199
Returns a bitmask with following possible flags:
193200
194201
* NPY_FPE_DIVIDEBYZERO
@@ -202,9 +209,13 @@ Those can be useful for precise floating point comparison.
202209
203210
Clears the floating point status. Returns the previous status mask.
204211
212+
Note that :c:func:`npy_clear_floatstatus_barrier` is preferable as it
213+
prevents agressive compiler optimizations reordering the call relative to
214+
the code setting the status, which could lead to incorrect results.
215+
205216
.. versionadded:: 1.9.0
206217
207-
.. c:function:: int npy_clear_floatstatus(char*)
218+
.. c:function:: int npy_clear_floatstatus_barrier(char*)
208219
209220
Clears the floating point status. A pointer to a local variable is passed in to
210221
prevent aggresive compiler optimizations from reodering this function call.

numpy/core/include/numpy/npy_math.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,13 @@ int npy_clear_floatstatus_barrier(char*);
528528
int npy_get_floatstatus_barrier(char*);
529529
/*
530530
* use caution with these - clang and gcc8.1 are known to reorder calls
531-
* to this form of the function which can defeat the check
531+
* to this form of the function which can defeat the check. The _barrier
532+
* form of the call is preferable, where the argument is
533+
* (char*)&local_variable
532534
*/
533535
int npy_clear_floatstatus(void);
534536
int npy_get_floatstatus(void);
537+
535538
void npy_set_floatstatus_divbyzero(void);
536539
void npy_set_floatstatus_overflow(void);
537540
void npy_set_floatstatus_underflow(void);

0 commit comments

Comments
 (0)