codac 2.0.0
Loading...
Searching...
No Matches
codac2_math.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <gaol/gaol_interval.h>
13#include <numbers>
14#include <cmath>
15
16namespace codac2
17{
18 const double oo = []() {
19
20 // (from IBEX lib, main author: Gilles Chabert)
21 // We use Gaol not in PRESERVE_ROUNDING mode, thus
22 // assuming the rounding mode is always set upward.
23 // Calling this function in the initialization of
24 // the 'oo' constant should be enough as this constant
25 // is initialized before the first Codac function call occurs.
26 gaol::round_upward();
27
28 return std::numeric_limits<double>::infinity();
29 }();
30
31 constexpr double PI = std::numbers::pi; // Need C++20
32
33 template<typename T>
34 requires std::is_arithmetic_v<T>
35 inline constexpr int sign(T x)
36 {
37 return (x > T(0)) - (x < T(0));
38 }
39
40 inline int integer(double x)
41 {
42 return (int)x;
43 }
44
45 inline double pow(double v, double p)
46 {
47 return v < 0 ? -std::pow(-v,p) : std::pow(v,p);
48 }
49
50 inline double root(double v, double p)
51 {
52 return pow(v, 1./p);
53 }
54
55 template<typename T>
56 inline bool is_nan(const T& x)
57 {
58 if constexpr(std::is_arithmetic_v<T>)
59 return std::isnan(x);
60 else
61 return x.is_nan();
62 }
63}
bool is_nan() const
Checks if any coefficient in the matrix is NaN.
Definition codac2_MatrixBase_addons_Base.h:68
Definition codac2_OctaSym.h:21
Interval pow(const Interval &x, int n)
Returns , .
Definition codac2_Interval_operations_impl.h:33
Interval root(const Interval &x, int p)
Returns the p-th root: .
Definition codac2_Interval_operations_impl.h:60
Interval integer(const Interval &x)
Returns the largest integer interval included in .
Definition codac2_Interval_operations_impl.h:284
Interval sign(const Interval &x)
Returns .
Definition codac2_Interval_operations_impl.h:279