Skip to content

Commit 18d9307

Browse files
committed
BUG: Fix Precise options and doc comment for it
1 parent 2c6746f commit 18d9307

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

npsr/common.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,42 @@ struct FPExceptions {
5151
static constexpr auto kUnderflow = FE_UNDERFLOW;
5252
};
5353

54+
/**
55+
* @brief RAII floating-point precision control class
56+
*
57+
* The Precise class provides automatic management of floating-point environment
58+
* settings during its lifetime. It uses RAII principles to save the current
59+
* floating-point state on construction and restore it on destruction.
60+
*
61+
* The class is configured using variadic template arguments that specify
62+
* the desired floating-point behavior through tag types.
63+
*
64+
* **IMPORTANT PERFORMANCE NOTE**: Create the Precise object BEFORE loops,
65+
* not inside them. The constructor and destructor have overhead from saving
66+
* and restoring floating-point state, so it should be done once per
67+
* computational scope, not per iteration.
68+
*
69+
* @tparam Args Variadic template arguments for configuration flags
70+
*
71+
* @example
72+
* ```cpp
73+
* using namespace hwy::HWY_NAMESPACE;
74+
* using namespace npsr;
75+
* using namespace npsr::HWY_NAMESPACE;
76+
*
77+
* Precise precise = {kLowAccuracy, kNoSpecialCases, kNoLargeArgument};
78+
* const ScalableTag<float> d;
79+
* typename V = Vec<DFromV<SclableTag>>;
80+
* for (size_t i = 0; i < n; i += Lanes(d)) {
81+
* V input = LoadU(d, &input[i]);
82+
* V result = Sin(precise, input);
83+
* StoreU(result, d, &output[i]);
84+
* }
85+
* ```
86+
*/
5487
template <typename... Args> class Precise {
5588
public:
56-
Precise() {
89+
Precise(Args...) {
5790
if constexpr (!kNoExceptions) {
5891
fegetexceptflag(&_exceptions, FE_ALL_EXCEPT);
5992
}

0 commit comments

Comments
 (0)