2323HWY_BEFORE_NAMESPACE ();
2424
2525namespace npsr ::HWY_NAMESPACE::trig {
26-
2726/* *
2827 * @brief Unified sine/cosine implementation with configurable precision
2928 *
@@ -32,13 +31,13 @@ namespace npsr::HWY_NAMESPACE::trig {
3231 * - Input magnitude (standard vs extended precision for large arguments)
3332 * - Special case handling (NaN, Inf)
3433 *
35- * @tparam IS_COS true for cosine, false for sine
34+ * @tparam OP Operation type: kSin or kCos
3635 * @tparam Prec Precise configuration class with accuracy/feature flags
3736 * @tparam V Highway vector type
3837 *
3938 * @param prec Precise object controlling FP environment and exceptions
4039 * @param x Input vector
41- * @return sin(x) or cos(x) depending on IS_COS
40+ * @return sin(x) or cos(x) depending on OP
4241 *
4342 * Algorithm selection:
4443 * 1. If kLowAccuracy: Use Low<> (Cody-Waite with minimal polynomial)
@@ -49,8 +48,8 @@ namespace npsr::HWY_NAMESPACE::trig {
4948 * - Float: |x| > 10,000 (empirically chosen for accuracy)
5049 * - Double: |x| > 2^24 (16,777,216 - where 53-bit mantissa loses precision)
5150 */
52- template <bool IS_COS , typename Prec, typename V>
53- HWY_API V SinCos (Prec &prec, V x) {
51+ template <Operation OP , typename Prec, typename V>
52+ NPSR_INTRIN V Trig (Prec &prec, V x) {
5453 using namespace hwy ::HWY_NAMESPACE;
5554 constexpr bool kIsSingle = std::is_same_v<TFromV<V>, float >;
5655 const DFromV<V> d;
@@ -59,19 +58,19 @@ HWY_API V SinCos(Prec &prec, V x) {
5958 if constexpr (Prec::kLowAccuracy ) {
6059 // Low precision: Cody-Waite reduction with degree-9 polynomial
6160 // Error: ~2 ULP and 3~ for non-fma
62- ret = Low<IS_COS >(x);
61+ ret = Low<OP >(x);
6362 } else {
6463 // High precision: π/16 reduction with table lookup + polynomial
6564 // Error: ~1 ULP
66- ret = High<IS_COS >(x);
65+ ret = High<OP >(x);
6766 }
6867 // Step 2: Handle special cases (NaN, Inf) if enabled
6968 auto is_finite = IsFinite (x);
7069 if constexpr (Prec::kSpecialCases ) {
7170 // IEEE 754 requires: sin(±∞) = NaN, cos(±∞) = NaN
7271 ret = IfThenElse (is_finite, ret, NaN (d));
7372 // -0.0 should return -0.0 for sine
74- if constexpr (!IS_COS ) {
73+ if constexpr (OP == Operation:: kSin ) {
7574 ret = IfThenElse (Eq (x, Set (d, 0.0 )), x, ret);
7675 }
7776 }
@@ -89,7 +88,7 @@ HWY_API V SinCos(Prec &prec, V x) {
8988 if (HWY_UNLIKELY (!AllFalse (d, has_large_arg))) {
9089 // Payne-Hanek reduction: Uses ~96-bit (float) or ~192-bit (double)
9190 // precision for 4/π to maintain accuracy for huge arguments
92- ret = IfThenElse (has_large_arg, Extended<IS_COS >(x), ret);
91+ ret = IfThenElse (has_large_arg, Extended<OP >(x), ret);
9392 }
9493 }
9594 // Step 4: Raise invalid operation exception for infinity inputs
@@ -107,41 +106,45 @@ namespace npsr::HWY_NAMESPACE {
107106/* *
108107 * @brief Compute sine of vector elements with configurable precision
109108 *
110- * @tparam Prec Precise configuration (e.g., Precise< kLowAccuracy> )
109+ * @tparam Prec Precise configuration (e.g., Precise{ kLowAccuracy} )
111110 * @tparam V Highway vector type
112111 * @param prec Precise object managing FP environment
113112 * @param x Input vector
114113 * @return sin(x) for each element
115114 *
116115 * @example
117116 * ```cpp
118- * Precise<kHighAccuracy> prec;
117+ * Precise prec{
118+ * kLowAccuracy, kNoLargeArgument, kNoExceptions, kNoSpecialCases
119+ * };
119120 * auto result = Sin(prec, input_vector);
120121 * ```
121122 */
122123template <typename Prec, typename V>
123- HWY_API V Sin (Prec &prec, V x) {
124- return trig::SinCos< false >(prec, x);
124+ NPSR_INTRIN V Sin (Prec &prec, V x) {
125+ return trig::Trig<trig::Operation:: kSin >(prec, x);
125126}
126127
127128/* *
128129 * @brief Compute cosine of vector elements with configurable precision
129130 *
130- * @tparam Prec Precise configuration (e.g., Precise< kLowAccuracy> )
131+ * @tparam Prec Precise configuration (e.g., Precise{ kLowAccuracy} )
131132 * @tparam V Highway vector type
132133 * @param prec Precise object managing FP environment
133134 * @param x Input vector
134135 * @return cos(x) for each element
135136 *
136137 * @example
137138 * ```cpp
138- * Precise<kNoLargeArgument, kNoSpecialCases> prec;
139+ * Precise prec{
140+ * kLowAccuracy, kNoLargeArgument, kNoExceptions, kNoSpecialCases
141+ * };
139142 * auto result = Cos(prec, input_vector);
140143 * ```
141144 */
142145template <typename Prec, typename V>
143- HWY_API V Cos (Prec &prec, V x) {
144- return trig::SinCos< true >(prec, x);
146+ NPSR_INTRIN V Cos (Prec &prec, V x) {
147+ return trig::Trig<trig::Operation:: kCos >(prec, x);
145148}
146149
147150} // namespace npsr::HWY_NAMESPACE
0 commit comments