-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathproduct.h
33 lines (27 loc) · 802 Bytes
/
product.h
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
#ifndef FASTEXP_PRODUCT_H
#define FASTEXP_PRODUCT_H
namespace fastexp {
template<typename Real, size_t degree, size_t i>
struct Recursion {
static Real evaluate(Real x) {
constexpr Real c = 1.0 / static_cast<Real>(1u << degree);
x = Recursion<Real, degree, i + 1>::evaluate(x);
return x * x;
}
};
template<typename Real, size_t degree>
struct Recursion<Real, degree, degree> {
static Real evaluate(Real x) {
constexpr Real c = 1.0 / static_cast<Real>(1u << degree);
x = 1.0 + c * x;
return x;
}
};
template<typename Real, size_t degree>
struct Product {
static Real evaluate(Real x) {
return Recursion<Real, degree, 0>::evaluate(x);
}
};
} // fastexp
#endif // FASTEXP_PRODUCT_H