-
Notifications
You must be signed in to change notification settings - Fork 2
/
interval.hpp
185 lines (167 loc) · 4.87 KB
/
interval.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// any implementation of interval you want to do
// you can do it here
// alternatively you can also link link libraries and define the type here
// but whatever you do, remember you need to define lower and upper function for your interval
// this is for the convenience of yourself so that you don't need to define it over and over
// in the computation part
#pragma once
#include <stdlib.h>
#include <functional>
#include <random>
// ================================================================
// ================================================================
// include filib c version interval
// do not change the order, always put this one first
// otherwise there gonna be some error
// and id rather not deal with those errors
#include "filib/interval.hpp"
typedef interval fic_interval;
#define fic_interval(v) \
{ \
v, v \
}
double lower(fic_interval v)
{
return v.INF;
}
double upper(fic_interval v)
{
return v.SUP;
}
// ================================================================
// ================================================================
// ==============================================================================================
// ==============================================================================================
// include boost interval
#if defined(__APPLE__)
#warning "__APPLE__ defined so explicitly defining __USE_ISOC99"
#define __USE_ISOC99
#endif
#include "boost/numeric/interval.hpp"
namespace interval_options
{
typedef boost::numeric::interval_lib::checking_base<double> CheckingPolicy;
} // namespace interval_options
#if defined(__APPLE__)
typedef boost::numeric::interval<
double,
boost::numeric::interval_lib::policies<
boost::numeric::interval_lib::save_state<
boost::numeric::interval_lib::rounded_transc_std<double>>,
interval_options::CheckingPolicy>>
boost_interval;
#else
typedef boost::numeric::interval<
double,
boost::numeric::interval_lib::policies<
boost::numeric::interval_lib::save_state<
boost::numeric::interval_lib::rounded_transc_std<double>>,
interval_options::CheckingPolicy>>
boost_interval;
#endif
double lower(boost_interval v)
{
return v.lower();
}
double upper(boost_interval v)
{
return v.upper();
}
// ==============================================================================================
// ==============================================================================================
// ==================================================================================================================
// ==================================================================================================================
// include filib c++ version interval
#ifdef USE_FILIB_PLUSPLUS
#include "interval/interval.hpp"
typedef filib::interval<double, filib::native_switched, filib::i_mode_normal> fi_native_switched;
typedef filib::interval<double, filib::pred_succ_rounding, filib::i_mode_normal> fi_pred_succ;
typedef filib::interval<double, filib::multiplicative, filib::i_mode_normal> fi_multiplicative;
template <typename T>
double lower(T v)
{
return v.inf();
}
template <typename T>
double upper(T v)
{
return v.sup();
}
#endif
// ==================================================================================================================
// ==================================================================================================================
#include <BIAS/Bias0.h>
#include <BIAS/BiasF.h>
#include <BiasRnd.h>
#define BIASINTERVAL(v) \
{ \
v, v \
}
double lower(BIASINTERVAL v)
{
return v.inf;
}
double upper(BIASINTERVAL v)
{
return v.sup;
}
BIASINTERVAL operator+(BIASINTERVAL a, BIASINTERVAL b)
{
BIASINTERVAL result;
BiasAddII(&result, &a, &b);
return result;
}
BIASINTERVAL operator-(BIASINTERVAL a, BIASINTERVAL b)
{
BIASINTERVAL result;
BiasSubII(&result, &a, &b);
return result;
}
BIASINTERVAL operator*(BIASINTERVAL a, BIASINTERVAL b)
{
BIASINTERVAL result;
BiasMulII(&result, &a, &b);
return result;
}
BIASINTERVAL operator/(BIASINTERVAL a, BIASINTERVAL b)
{
BIASINTERVAL result;
BiasDivII(&result, &a, &b);
return result;
}
BIASINTERVAL sqrt(BIASINTERVAL a)
{
BIASINTERVAL result;
BiasSqrt(&result, &a);
return result;
}
BIASINTERVAL exp(BIASINTERVAL a)
{
BIASINTERVAL result;
BiasExp(&result, &a);
return result;
}
BIASINTERVAL sin(BIASINTERVAL a)
{
BIASINTERVAL result;
BiasSin(&result, &a);
return result;
}
BIASINTERVAL cos(BIASINTERVAL a)
{
BIASINTERVAL result;
BiasCos(&result, &a);
return result;
}
BIASINTERVAL tan(BIASINTERVAL a)
{
BIASINTERVAL result;
BiasTan(&result, &a);
return result;
}
BIASINTERVAL atan(BIASINTERVAL a)
{
BIASINTERVAL result;
BiasArcTan(&result, &a);
return result;
}