/** * @file mix_cc/matheval/math.hpp * @brief 数学函数 * @author Cat (null.null.null@qq.com) * @version 0.1 * @date 2021-09-17 * * Copyright: Baosight Co. Ltd. * DO NOT COPY/USE WITHOUT PERMISSION * */ #ifndef MATHEVAL_IMPLEMENTATION #error "Do not include math.hpp directly!" #endif #pragma once #include #include namespace mix_cc{ namespace matheval { namespace math { /// @brief Sign function template T sgn(T x) { return (T{0} < x) - (x < T{0}); } /// @brief isnan function with adjusted return type template T isnan(T x) { return std::isnan(x); } /// @brief isinf function with adjusted return type template T isinf(T x) { return std::isinf(x); } /// @brief Convert radians to degrees template T deg(T x) { return x * boost::math::constants::radian(); } /// @brief Convert degrees to radians template T rad(T x) { return x * boost::math::constants::degree(); } /// @brief unary plus template T plus(T x) { return x; } /// @brief binary plus template T plus(T x, T y) { return x + y; } /// @brief unary minus template T minus(T x) { return -x; } /// @brief binary minus template T minus(T x, T y) { return x - y; } /// @brief multiply template T multiplies(T x, T y) { return x * y; } /// @brief divide template T divides(T x, T y) { return x / y; } /// @brief unary not template T unary_not(T x) { return !x; } /// @brief logical and template T logical_and(T x, T y) { return x && y; } /// @brief logical or template T logical_or(T x, T y) { return x || y; } /// @brief less template T less(T x, T y) { return x < y; } /// @brief less equals template T less_equals(T x, T y) { return x <= y; } /// @brief greater template T greater(T x, T y) { return x > y; } /// @brief greater equals template T greater_equals(T x, T y) { return x >= y; } /// @brief equals template T equals(T x, T y) { return x == y; } /// @brief not equals template T not_equals(T x, T y) { return x != y; } } // namespace math } // namespace matheval }