kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 2e45c6353b29efb760c8dba84b882dd5751be5e7
parent 9b4eaa22b7a7ade5815990258d8dab62fbb2a146
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date:   Fri, 19 Aug 2016 16:25:25 +0300

Added documentation for math functions

Diffstat:
Minclude/kfr/base/abs.hpp | 15++++++++++-----
Minclude/kfr/base/asin_acos.hpp | 21++++++++++++++++-----
Minclude/kfr/base/atan.hpp | 35+++++++++++++++++++++++++++++++----
Minclude/kfr/base/complex.hpp | 12++++++++----
Minclude/kfr/base/cpuid_auto.hpp | 12++++++++----
Minclude/kfr/base/logical.hpp | 16++++++++++------
Minclude/kfr/base/min_max.hpp | 32++++++++++++++++++++++++++++----
Minclude/kfr/base/operators.hpp | 64+++++++++++++++++++++++++++++++++++++++++++++-------------------
Minclude/kfr/base/select.hpp | 18++++++++++++++----
Minclude/kfr/base/sin_cos.hpp | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Minclude/kfr/base/sqrt.hpp | 14++++++++++----
11 files changed, 282 insertions(+), 64 deletions(-)

diff --git a/include/kfr/base/abs.hpp b/include/kfr/base/abs.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -111,13 +111,18 @@ KFR_I_CONVERTER(abs) } KFR_I_FN(abs) - +/** + * @brief Returns the absolute value of x. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN T1 abs(const T1& x) { return intrinsics::abs(x); } +/** + * @brief Returns template expression that returns the absolute value of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::abs, E1> abs(E1&& x) { diff --git a/include/kfr/base/asin_acos.hpp b/include/kfr/base/asin_acos.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -55,24 +55,35 @@ KFR_I_FLT_CONVERTER(acos) KFR_I_FN(asin) KFR_I_FN(acos) +/** + * @brief Returns the arc sine of x. The returned angle is in the range \f$-\pi/2\f$ through \f$\pi/2\f$. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> asin(const T1& x) { return intrinsics::asin(x); } +/** + * @brief Returns template expression that returns the arc sine of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::asin, E1> asin(E1&& x) { return { fn::asin(), std::forward<E1>(x) }; } - +/** + * @brief Returns the arc cosine of x. The returned angle is in the range 0 through \f$\pi\f$. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> acos(const T1& x) { return intrinsics::acos(x); } +/** + * @brief Returns template expression that returns the arc cosine of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::acos, E1> acos(E1&& x) { diff --git a/include/kfr/base/atan.hpp b/include/kfr/base/atan.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -225,48 +225,75 @@ KFR_I_FN(atandeg) KFR_I_FN(atan2) KFR_I_FN(atan2deg) +/** + * @brief Returns the arc tangent of x. The returned angle is in the range \f$-\pi/2\f$ through + * \f$\pi/2\f$. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> atan(const T1& x) { return intrinsics::atan(x); } +/** + * @brief Returns template expression that returns the arc tangent of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::atan, E1> atan(E1&& x) { return { fn::atan(), std::forward<E1>(x) }; } +/** + * @brief Returns the arc tangent of the x, expressed in degrees. The returned angle is in the range -90 + * through 90. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> atandeg(const T1& x) { return intrinsics::atandeg(x); } +/** + * @brief Returns template expression that returns the arc tangent of the x, expressed in degrees. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::atandeg, E1> atandeg(E1&& x) { return { fn::atandeg(), std::forward<E1>(x) }; } +/** + * @brief Returns the arc tangent of y/x using the signs of arguments to determine the correct quadrant. + */ template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>::value)> KFR_INTRIN common_type<T1, T2> atan2(const T1& x, const T2& y) { return intrinsics::atan2(x, y); } +/** + * @brief Returns template expression that returns the arc tangent of y/x. + */ template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> KFR_INTRIN internal::expression_function<fn::atan2, E1, E2> atan2(E1&& x, E2&& y) { return { fn::atan2(), std::forward<E1>(x), std::forward<E2>(y) }; } +/** + * @brief Returns the arc tangent of y/x (expressed in degrees) using the signs of arguments to determine the + * correct quadrant. + */ template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>::value)> KFR_INTRIN common_type<T1, T2> atan2deg(const T1& x, const T2& y) { return intrinsics::atan2deg(x, y); } +/** + * @brief Returns template expression that returns the arc tangent of y/x (expressed in degrees). + */ template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> KFR_INTRIN internal::expression_function<fn::atan2deg, E1, E2> atan2deg(E1&& x, E2&& y) { diff --git a/include/kfr/base/complex.hpp b/include/kfr/base/complex.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -50,6 +50,10 @@ using complex = std::complex<T>; #else #ifndef KFR_CUSTOM_COMPLEX +/** + * @brief Represents the complex numbers. If KFR_STD_COMPLEX is defined, then kfr::complex is an alias for + * std::complex. + */ template <typename T> struct complex { diff --git a/include/kfr/base/cpuid_auto.hpp b/include/kfr/base/cpuid_auto.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -52,5 +52,9 @@ CMT_INLINE char init_dummyvar() static char dummyvar = init_dummyvar(); } + +/** + * @brief Returns cpu instruction set detected at runtime. + */ CMT_INLINE cpu_t get_cpu() { return internal::cpu_v(); } } diff --git a/include/kfr/base/logical.hpp b/include/kfr/base/logical.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -251,14 +251,18 @@ KFR_SINTRIN bool bittestall(const vec<T, N>& x, const vec<T, N>& y) #endif } -/// Returns x[0] && x[1] && ... && x[N-1] +/** + * @brief Returns x[0] && x[1] && ... && x[N-1] + */ template <typename T, size_t N> KFR_SINTRIN bool all(const mask<T, N>& x) { return intrinsics::bittestall(x.asvec()); } -/// Returns x[0] || x[1] || ... || x[N-1] +/** + * @brief Returns x[0] || x[1] || ... || x[N-1] + */ template <typename T, size_t N> KFR_SINTRIN bool any(const mask<T, N>& x) { diff --git a/include/kfr/base/min_max.hpp b/include/kfr/base/min_max.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -199,6 +199,9 @@ KFR_I_FN(max) KFR_I_FN(absmin) KFR_I_FN(absmax) +/** + * @brief Returns the smaller of two values. + */ template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>::value), typename Tout = common_type<T1, T2>> KFR_INTRIN Tout min(const T1& x, const T2& y) @@ -206,12 +209,18 @@ KFR_INTRIN Tout min(const T1& x, const T2& y) return intrinsics::min(x, y); } +/** + * @brief Returns template expression that returns the smaller of two values. + */ template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> KFR_INTRIN internal::expression_function<fn::min, E1, E2> min(E1&& x, E2&& y) { return { fn::min(), std::forward<E1>(x), std::forward<E2>(y) }; } +/** + * @brief Returns the greater of two values. + */ template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>::value), typename Tout = common_type<T1, T2>> KFR_INTRIN Tout max(const T1& x, const T2& y) @@ -219,12 +228,18 @@ KFR_INTRIN Tout max(const T1& x, const T2& y) return intrinsics::max(x, y); } +/** + * @brief Returns template expression that returns the greater of two values. + */ template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> KFR_INTRIN internal::expression_function<fn::max, E1, E2> max(E1&& x, E2&& y) { return { fn::max(), std::forward<E1>(x), std::forward<E2>(y) }; } +/** + * @brief Returns the smaller in magnitude of two values. + */ template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>::value), typename Tout = common_type<T1, T2>> KFR_INTRIN Tout absmin(const T1& x, const T2& y) @@ -232,12 +247,18 @@ KFR_INTRIN Tout absmin(const T1& x, const T2& y) return intrinsics::absmin(x, y); } +/** + * @brief Returns template expression that returns the smaller in magnitude of two values. + */ template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> KFR_INTRIN internal::expression_function<fn::absmin, E1, E2> absmin(E1&& x, E2&& y) { return { fn::absmin(), std::forward<E1>(x), std::forward<E2>(y) }; } +/** + * @brief Returns the greater in magnitude of two values. + */ template <typename T1, typename T2, KFR_ENABLE_IF(is_numeric_args<T1, T2>::value), typename Tout = common_type<T1, T2>> KFR_INTRIN Tout absmax(const T1& x, const T2& y) @@ -245,6 +266,9 @@ KFR_INTRIN Tout absmax(const T1& x, const T2& y) return intrinsics::absmax(x, y); } +/** + * @brief Returns template expression that returns the greater in magnitude of two values. + */ template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> KFR_INTRIN internal::expression_function<fn::absmax, E1, E2> absmax(E1&& x, E2&& y) { diff --git a/include/kfr/base/operators.hpp b/include/kfr/base/operators.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -64,6 +64,10 @@ constexpr inline T add(T x) { return x; } + +/** + * @brief Returns sum of all the arguments passed to a function. + */ template <typename T1, typename T2, typename... Ts> constexpr inline common_type<T1, T2, Ts...> add(T1 x, T2 y, Ts... rest) { @@ -76,6 +80,9 @@ constexpr inline T add(initialvalue<T>) } KFR_FN(add) +/** + * @brief Returns template expression that returns sum of all the arguments passed to a function. + */ template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> CMT_INLINE internal::expression_function<fn_add, E1, E2> add(E1&& x, E2&& y) { @@ -110,6 +117,10 @@ constexpr inline T1 mul(T1 x) { return x; } + +/** + * @brief Returns product of all the arguments passed to a function. + */ template <typename T1, typename T2, typename... Ts> constexpr inline common_type<T1, T2, Ts...> mul(T1 x, T2 y, Ts... rest) { @@ -122,6 +133,10 @@ constexpr inline T mul(initialvalue<T>) return T(1); } KFR_FN(mul) + +/** + * @brief Returns template expression that returns product of all the arguments passed to a function. + */ template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> CMT_INLINE internal::expression_function<fn_mul, E1, E2> mul(E1&& x, E2&& y) { @@ -133,18 +148,28 @@ CMT_INLINE internal::expression_function<fn_mul, E1> mul(E1&& x, E2&& y, E3&& z) return { fn_mul(), std::forward<E1>(x), std::forward<E2>(y), std::forward<E3>(z) }; } +/** + * @brief Returns square of x. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> constexpr inline T1 sqr(T1 x) { return x * x; } KFR_FN(sqr) + +/** + * @brief Returns template expression that returns square of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> CMT_INLINE internal::expression_function<fn_sqr, E1> sqr(E1&& x) { return { fn_sqr(), std::forward<E1>(x) }; } +/** + * @brief Returns cube of x. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> constexpr inline T1 cub(T1 x) { @@ -152,6 +177,9 @@ constexpr inline T1 cub(T1 x) } KFR_FN(cub) +/** + * @brief Returns template expression that returns cube of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> CMT_INLINE internal::expression_function<fn_cub, E1> cub(E1&& x) { @@ -230,9 +258,7 @@ KFR_FN(ipow) template <typename E1, typename E2, KFR_ENABLE_IF(is_input_expressions<E1, E2>::value)> CMT_INLINE internal::expression_function<fn_ipow, E1, E2> ipow(E1&& x, E2&& b) { - return { fn_ipow(), std::forward<E1>(x), std::forward<E2>(b) - - }; + return { fn_ipow(), std::forward<E1>(x), std::forward<E2>(b) }; } /// Return square of the sum of all arguments @@ -406,13 +432,13 @@ KFR_FN(greater) KFR_FN(lessorequal) KFR_FN(greaterorequal) -/// Fused Multiply-Add +/// @brief Fused Multiply-Add template <typename T1, typename T2, typename T3> constexpr inline common_type<T1, T2, T3> fmadd(T1 x, T2 y, T3 z) { return x * y + z; } -/// Fused Multiply-Sub +/// @brief Fused Multiply-Sub template <typename T1, typename T2, typename T3> constexpr inline common_type<T1, T2, T3> fmsub(T1 x, T2 y, T3 z) { @@ -421,7 +447,7 @@ constexpr inline common_type<T1, T2, T3> fmsub(T1 x, T2 y, T3 z) KFR_FN(fmadd) KFR_FN(fmsub) -/// Linear blend of `x` and `y` (`c` must be in the range 0...+1) +/// @brief Linear blend of `x` and `y` (`c` must be in the range 0...+1) /// Returns `x + ( y - x ) * c` template <typename T1, typename T2, typename T3> constexpr inline common_type<T1, T2, T3> mix(T1 c, T2 x, T3 y) @@ -429,7 +455,7 @@ constexpr inline common_type<T1, T2, T3> mix(T1 c, T2 x, T3 y) return fmadd(c, y - x, x); } -/// Linear blend of `x` and `y` (`c` must be in the range -1...+1) +/// @brief Linear blend of `x` and `y` (`c` must be in the range -1...+1) template <typename T1, typename T2, typename T3> constexpr inline common_type<T1, T2, T3> mixs(T1 c, T2 x, T3 y) { @@ -454,7 +480,7 @@ constexpr CMT_INLINE T1 horner(T1 x, T2 c0, T3 c1, Ts... values) } } -/// Calculate polynomial using Horner's method +/// @brief Calculate polynomial using Horner's method /// /// ``horner(x, 1, 2, 3)`` is equivalent to \(3x^2 + 2x + 1\) template <typename T1, typename... Ts> @@ -464,7 +490,7 @@ constexpr CMT_INLINE T1 horner(T1 x, Ts... c) } KFR_FN(horner) -/// Calculate Multiplicative Inverse of `x` +/// @brief Calculate Multiplicative Inverse of `x` /// Returns `1/x` template <typename T> constexpr CMT_INLINE T reciprocal(T x) @@ -524,7 +550,7 @@ CMT_INLINE mask<T, N> iszero(const vec<T, N>& x) return x == T(); } -/// Swap byte order +/// @brief Swap byte order template <typename T, size_t N, KFR_ENABLE_IF(sizeof(vec<T, N>) > 8)> CMT_INLINE vec<T, N> swapbyteorder(const vec<T, N>& x) { @@ -547,7 +573,7 @@ CMT_INLINE T swapbyteorder(T x) } KFR_FN(swapbyteorder) -/// Sum all elements of the vector +/// @brief Sum all elements of the vector template <typename T, size_t N> CMT_INLINE T hadd(const vec<T, N>& value) { @@ -555,7 +581,7 @@ CMT_INLINE T hadd(const vec<T, N>& value) } KFR_FN(hadd) -/// Multiply all elements of the vector +/// @brief Multiply all elements of the vector template <typename T, size_t N> CMT_INLINE T hmul(const vec<T, N>& value) { @@ -582,7 +608,7 @@ CMT_INLINE T hbitwisexor(const vec<T, N>& value) } KFR_FN(hbitwisexor) -/// Calculate the Dot-Product of two vectors +/// @brief Calculate the Dot-Product of two vectors template <typename T, size_t N> CMT_INLINE T dot(const vec<T, N>& x, const vec<T, N>& y) { @@ -590,7 +616,7 @@ CMT_INLINE T dot(const vec<T, N>& x, const vec<T, N>& y) } KFR_FN(dot) -/// Calculate the Arithmetic mean of all elements in the vector +/// @brief Calculate the Arithmetic mean of all elements in the vector template <typename T, size_t N> CMT_INLINE T avg(const vec<T, N>& value) { @@ -598,7 +624,7 @@ CMT_INLINE T avg(const vec<T, N>& value) } KFR_FN(avg) -/// Calculate the RMS of all elements in the vector +/// @brief Calculate the RMS of all elements in the vector template <typename T, size_t N> CMT_INLINE T rms(const vec<T, N>& value) { diff --git a/include/kfr/base/select.hpp b/include/kfr/base/select.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -201,6 +201,12 @@ KFR_SINTRIN vec<T, N> select(const mask<T, N>& m, const vec<T, N>& x, const vec< } KFR_I_FN(select) +/** + * @brief Returns x if m is true, otherwise return y. Order of the arguments is same as in ternary operator. + * @code + * return m ? x : y + * @endcode + */ template <typename T1, size_t N, typename T2, typename T3, KFR_ENABLE_IF(is_numeric_args<T1, T2, T3>::value), typename Tout = subtype<common_type<T2, T3>>> KFR_INTRIN vec<Tout, N> select(const mask<T1, N>& m, const T2& x, const T3& y) @@ -209,6 +215,10 @@ KFR_INTRIN vec<Tout, N> select(const mask<T1, N>& m, const T2& x, const T3& y) return intrinsics::select(bitcast<Tout>(m), static_cast<vec<Tout, N>>(x), static_cast<vec<Tout, N>>(y)); } +/** + * @brief Returns template expression that returns x if m is true, otherwise return y. Order of the arguments + * is same as in ternary operator. + */ template <typename E1, typename E2, typename E3, KFR_ENABLE_IF(is_input_expressions<E1, E2, E3>::value)> KFR_INTRIN internal::expression_function<fn::select, E1, E2, E3> select(E1&& m, E2&& x, E3&& y) { diff --git a/include/kfr/base/sin_cos.hpp b/include/kfr/base/sin_cos.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -344,144 +344,226 @@ KFR_I_FN(cossindeg) KFR_I_FN(sinc) +/** + * @brief Returns the trigonometric sine of x. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> sin(const T1& x) { return intrinsics::sin(x); } +/** + * @brief Returns template expression that returns the trigonometric sine of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::sin, E1> sin(E1&& x) { return { fn::sin(), std::forward<E1>(x) }; } +/** + * @brief Returns the trigonometric cosine of x. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> cos(const T1& x) { return intrinsics::cos(x); } +/** + * @brief Returns template expression that returns the trigonometric cosine of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::cos, E1> cos(E1&& x) { return { fn::cos(), std::forward<E1>(x) }; } +/** + * @brief Returns an approximation of the trigonometric sine of x. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> fastsin(const T1& x) { return intrinsics::fastsin(x); } +/** + * @brief Returns template expression that returns an approximation of the trigonometric sine of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::fastsin, E1> fastsin(E1&& x) { return { fn::fastsin(), std::forward<E1>(x) }; } +/** + * @brief Returns an approximation of the trigonometric cosine of x. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> fastcos(const T1& x) { return intrinsics::fastcos(x); } +/** + * @brief Returns template expression that returns an approximation of the trigonometric cosine of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::fastcos, E1> fastcos(E1&& x) { return { fn::fastcos(), std::forward<E1>(x) }; } +/** + * @brief Returns the trigonometric sine of the even elements of the x and cosine of the odd elements. x must + * be a vector. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> sincos(const T1& x) { return intrinsics::sincos(x); } +/** + * @brief Returns template expression that returns the trigonometric sine of the even elements of the x and + * cosine of the odd elements. x must be a vector. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::sincos, E1> sincos(E1&& x) { return { fn::sincos(), std::forward<E1>(x) }; } +/** + * @brief Returns the trigonometric cosine of the even elements of the x and sine of the odd elements. x must + * be a vector. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> cossin(const T1& x) { return intrinsics::cossin(x); } +/** + * @brief Returns template expression that returns the trigonometric cosine of the even elements of the x and + * sine of the odd elements. x must be a vector. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::cossin, E1> cossin(E1&& x) { return { fn::cossin(), std::forward<E1>(x) }; } +/** + * @brief Returns the trigonometric sine of the x (expressed in degrees). + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> sindeg(const T1& x) { return intrinsics::sindeg(x); } +/** + * @brief Returns template expression that returns the trigonometric sine of the x (expressed in degrees). + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::sindeg, E1> sindeg(E1&& x) { return { fn::sindeg(), std::forward<E1>(x) }; } +/** + * @brief Returns the trigonometric cosine of the x (expressed in degrees). + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> cosdeg(const T1& x) { return intrinsics::cosdeg(x); } +/** + * @brief Returns template expression that returns the trigonometric cosine of the x (expressed in degrees). + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::cosdeg, E1> cosdeg(E1&& x) { return { fn::cosdeg(), std::forward<E1>(x) }; } +/** + * @brief Returns an approximation of the trigonometric sine of the x (expressed in degrees). + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> fastsindeg(const T1& x) { return intrinsics::fastsindeg(x); } +/** + * @brief Returns template expression that returns an approximation of the trigonometric sine of the x + * (expressed in degrees). + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::fastsindeg, E1> fastsindeg(E1&& x) { return { fn::fastsindeg(), std::forward<E1>(x) }; } +/** + * @brief Returns an approximation of the trigonometric cosine of the x (expressed in degrees). + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> fastcosdeg(const T1& x) { return intrinsics::fastcosdeg(x); } +/** + * @brief Returns template expression that returns an approximation of the trigonometric cosine of the x + * (expressed in degrees). + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::fastcosdeg, E1> fastcosdeg(E1&& x) { return { fn::fastcosdeg(), std::forward<E1>(x) }; } +/** + * @brief Returns the trigonometric sine of the even elements of the x and cosine of the odd elements. x must + * be a vector and expressed in degrees. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> sincosdeg(const T1& x) { return intrinsics::sincosdeg(x); } +/** + * @brief Returns template expression that returns the trigonometric sine of the even elements of the x and + * cosine of the odd elements. x must be expressed in degrees. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::sincosdeg, E1> sincosdeg(E1&& x) { return { fn::sincosdeg(), std::forward<E1>(x) }; } +/** + * @brief Returns the trigonometric cosine of the even elements of the x and sine of the odd elements. x must + * be a vector and expressed in degrees. + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> cossindeg(const T1& x) { return intrinsics::cossindeg(x); } +/** + * @brief Returns template expression that returns the trigonometric cosine of the even elements of the x and + * sine of the odd elements. x must be expressed in degrees. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::cossindeg, E1> cossindeg(E1&& x) { @@ -489,7 +571,7 @@ KFR_INTRIN internal::expression_function<fn::cossindeg, E1> cossindeg(E1&& x) } /** - * \brief Returns the sinc function of the given x value + * @brief Returns the sinc function of x. * \f[ * sinc(x) = \frac{sin(x)}{x} * \f] @@ -500,30 +582,45 @@ KFR_INTRIN flt_type<T1> sinc(const T1& x) return intrinsics::sinc(x); } +/** + * @brief Returns template expression that returns the sinc function of x. + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::sinc, E1> sinc(E1&& x) { return { fn::sinc(), std::forward<E1>(x) }; } +/** + * @brief Returns the trigonometric sine of the angle 2x using sin(x) and cos(x). + */ template <typename T> KFR_SINTRIN T sin2x(const T& sinx, const T& cosx) { return 2 * sinx * cosx; } +/** + * @brief Returns the trigonometric sine of the angle 3x using sin(x) and cos(x). + */ template <typename T> KFR_SINTRIN T sin3x(const T& sinx, const T& cosx) { return sinx * (-1 + 4 * sqr(cosx)); } +/** + * @brief Returns the trigonometric cosine of the angle 2x using sin(x) and cos(x). + */ template <typename T> KFR_SINTRIN T cos2x(const T& sinx, const T& cosx) { return sqr(cosx) - sqr(sinx); } +/** + * @brief Returns the trigonometric cosine of the angle 3x using sin(x) and cos(x). + */ template <typename T> KFR_SINTRIN T cos3x(const T& sinx, const T& cosx) { diff --git a/include/kfr/base/sqrt.hpp b/include/kfr/base/sqrt.hpp @@ -4,20 +4,20 @@ /* Copyright (C) 2016 D Levin (https://www.kfrlib.com) This file is part of KFR - + KFR is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - + KFR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with KFR. - + If GPL is not suitable for your project, you must purchase a commercial license to use KFR. Buying a commercial license is mandatory as soon as you develop commercial activities without disclosing the source code of your own applications. @@ -63,12 +63,18 @@ KFR_I_FLT_CONVERTER(sqrt) } KFR_I_FN(sqrt) +/** + * @brief Returns the positive square root of the x. \f$\sqrt{x}\f$ + */ template <typename T1, KFR_ENABLE_IF(is_numeric<T1>::value)> KFR_INTRIN flt_type<T1> sqrt(const T1& x) { return intrinsics::sqrt(x); } +/** + * @brief Returns template expression that returns the positive square root of the x. \f$\sqrt{x}\f$ + */ template <typename E1, KFR_ENABLE_IF(is_input_expression<E1>::value)> KFR_INTRIN internal::expression_function<fn::sqrt, E1> sqrt(E1&& x) {