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 <3rd/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 inline int sign(double x)
34 {
35 return (x > 0) ? 1 : ((x < 0) ? -1 : 0);
36 }
37
38 inline int integer(double x)
39 {
40 return (int)x;
41 }
42
43 inline double pow(double v, double p)
44 {
45 return v < 0 ? -std::pow(-v,p) : std::pow(v,p);
46 }
47
48 inline double root(double v, double p)
49 {
50 return pow(v, 1./p);
51 }
52}
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