preCICE v3.1.2
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 {
8namespace math {
9
11inline int sign(double number)
12{
13 if (greater(number, 0.0)) {
14 return 1;
15 } else if (greater(0.0, number)) {
16 return -1;
17 }
18 return 0;
19}
20
22template <int iexp, typename T>
23inline constexpr T pow_int(const T x)
24{
25 static_assert(iexp >= 0, "Exponent must be an integer greater or equal to zero.");
26
27 if (iexp == 0)
28 return static_cast<T>(1.);
29 else
30 // exponentiation by squaring
31 return ((iexp % 2 == 1) ? x * pow_int<iexp / 2>(x * x) : pow_int<iexp / 2>(x * x));
32}
33
34} // namespace math
35} // namespace precice
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:23
int sign(double number)
Return the sign, one of {-1, 0, 1}.
Definition math.hpp:11
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type greater(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Main namespace of the precice library.