summaryrefslogtreecommitdiff
path: root/utils/star.h
blob: e7358ffa3464200f36bd8b9e3060a0b417c92010 (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>
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);
}

bool star(bool x) {
  return x;
}

#endif