summaryrefslogtreecommitdiff
path: root/utils/star.h
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-12 13:56:42 +0200
committerPatrick Simianer <p@simianer.de>2014-06-12 13:56:42 +0200
commita39aa79b18347e22ef36ebc0da5a7eb220bcb23f (patch)
tree2c0f3009f8e381002bfeb82c0ea3bd0c41125761 /utils/star.h
parent62bd9a4bdcea606d6ff2031fa4b207ef20caac31 (diff)
parent0e2f8d3d049f06afb08b4639c6a28aa5461cdc78 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'utils/star.h')
-rw-r--r--utils/star.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/utils/star.h b/utils/star.h
new file mode 100644
index 00000000..21977dc9
--- /dev/null
+++ b/utils/star.h
@@ -0,0 +1,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