preCICE v3.2.0
Loading...
Searching...
No Matches
math.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "math/constants.hpp"
5#include "math/la.hpp"
6
7namespace precice::math {
8
10inline int sign(double number)
11{
12 if (greater(number, 0.0)) {
13 return 1;
14 } else if (greater(0.0, number)) {
15 return -1;
16 }
17 return 0;
18}
19
21template <int iexp, typename T>
22inline constexpr T pow_int(const T x)
23{
24 static_assert(iexp >= 0, "Exponent must be an integer greater or equal to zero.");
25
26 if (iexp == 0)
27 return static_cast<T>(1.);
28 else
29 // exponentiation by squaring
30 return ((iexp % 2 == 1) ? x * pow_int<iexp / 2>(x * x) : pow_int<iexp / 2>(x * x));
31}
32
33} // namespace precice::math
provides general mathematical constants and functions.
Definition barycenter.cpp:9
constexpr T pow_int(const T x)
Computes the power of a given number by an integral exponent given at compile time,...
Definition math.hpp:22
int sign(double number)
Return the sign, one of {-1, 0, 1}.
Definition math.hpp:10
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type greater(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)