summaryrefslogtreecommitdiff
path: root/utils/star.h
blob: 01433d12c1dbe3029ceba74620eb5f7bebbad903 (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