LCOV - code coverage report
Current view: top level - src/qi - math.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 42 42 100.0 %
Date: 2022-11-05 14:57:37 Functions: 21 21 100.0 %

          Line data    Source code
       1             : #ifndef MATHEVAL_IMPLEMENTATION
       2             : #error "Do not include math.hpp directly!"
       3             : #endif
       4             : 
       5             : #pragma once
       6             : 
       7             : #include <boost/math/constants/constants.hpp>
       8             : 
       9             : #include <cmath>
      10             : 
      11             : namespace matheval {
      12             : 
      13             : namespace math {
      14             : 
      15             : /// @brief Sign function
      16             : template <typename T>
      17           1 : T sgn(T x) {
      18           1 :     return (T(0) < x) - (x < T(0));
      19             : }
      20             : 
      21             : /// @brief isnan function with adjusted return type
      22             : template <typename T>
      23           1 : T isnan(T x) {
      24           1 :     return std::isnan(x);
      25             : }
      26             : 
      27             : /// @brief isinf function with adjusted return type
      28             : template <typename T>
      29           1 : T isinf(T x) {
      30           1 :     return std::isinf(x);
      31             : }
      32             : 
      33             : /// @brief Convert radians to degrees
      34             : template <typename T>
      35           1 : T deg(T x) {
      36           1 :     return x * boost::math::constants::radian<T>();
      37             : }
      38             : 
      39             : /// @brief Convert degrees to radians
      40             : template <typename T>
      41           1 : T rad(T x) {
      42           1 :     return x * boost::math::constants::degree<T>();
      43             : }
      44             : 
      45             : /// @brief unary plus
      46             : template <typename T>
      47           2 : T plus(T x) {
      48           2 :     return x;
      49             : }
      50             : 
      51             : /// @brief binary plus
      52             : template <typename T>
      53           8 : T plus(T x, T y) {
      54           8 :     return x + y;
      55             : }
      56             : 
      57             : /// @brief unary minus
      58             : template <typename T>
      59           2 : T minus(T x) {
      60           2 :     return -x;
      61             : }
      62             : 
      63             : /// @brief binary minus
      64             : template <typename T>
      65           2 : T minus(T x, T y) {
      66           2 :     return x - y;
      67             : }
      68             : 
      69             : /// @brief multiply
      70             : template <typename T>
      71           6 : T multiplies(T x, T y) {
      72           6 :     return x * y;
      73             : }
      74             : 
      75             : /// @brief divide
      76             : template <typename T>
      77           6 : T divides(T x, T y) {
      78           6 :     return x / y;
      79             : }
      80             : 
      81             : /// @brief unary not
      82             : template <typename T>
      83           2 : T unary_not(T x) {
      84           2 :     return !x;
      85             : }
      86             : 
      87             : /// @brief logical and
      88             : template <typename T>
      89          10 : T logical_and(T x, T y) {
      90          10 :     return x && y;
      91             : }
      92             : 
      93             : /// @brief logical or
      94             : template <typename T>
      95          10 : T logical_or(T x, T y) {
      96          10 :     return x || y;
      97             : }
      98             : 
      99             : /// @brief less
     100             : template <typename T>
     101          13 : T less(T x, T y) {
     102          13 :     return x < y;
     103             : }
     104             : 
     105             : /// @brief less equals
     106             : template <typename T>
     107          13 : T less_equals(T x, T y) {
     108          13 :     return x <= y;
     109             : }
     110             : 
     111             : /// @brief greater
     112             : template <typename T>
     113          13 : T greater(T x, T y) {
     114          13 :     return x > y;
     115             : }
     116             : 
     117             : /// @brief greater equals
     118             : template <typename T>
     119          13 : T greater_equals(T x, T y) {
     120          13 :     return x >= y;
     121             : }
     122             : 
     123             : /// @brief equals
     124             : template <typename T>
     125          13 : T equals(T x, T y) {
     126          13 :     return x == y;
     127             : }
     128             : 
     129             : /// @brief not equals
     130             : template <typename T>
     131          13 : T not_equals(T x, T y) {
     132          13 :     return x != y;
     133             : }
     134             : 
     135             : /// @brief if then else
     136             : template <typename T>
     137           2 : T ifthenelse(T cond, T t, T f) {
     138           2 :     return (cond ? t : f);
     139             : }
     140             : 
     141             : } // namespace math
     142             : 
     143             : } // namespace matheval

Generated by: LCOV version 1.14