@@ -51,9 +51,42 @@ struct FPExceptions {
51
51
static constexpr auto kUnderflow = FE_UNDERFLOW;
52
52
};
53
53
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
+ */
54
87
template <typename ... Args> class Precise {
55
88
public:
56
- Precise () {
89
+ Precise (Args... ) {
57
90
if constexpr (!kNoExceptions ) {
58
91
fegetexceptflag (&_exceptions, FE_ALL_EXCEPT);
59
92
}
0 commit comments