blob: 21977dc9bfe25d879306cd9135b5fe6eabd33b34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#ifndef _STAR_H_
#define _STAR_H_
// star(x) computes the infinite sum x^0 + x^1 + x^2 + ...
template <typename T>
inline T star(const T& x) {
if (!x) return T();
if (x > T(1)) return std::numeric_limits<T>::infinity();
if (x < -T(1)) return -std::numeric_limits<T>::infinity();
return T(1) / (T(1) - x);
}
inline bool star(bool x) {
return x;
}
#endif
|