diff options
author | Chris Dyer <redpony@gmail.com> | 2014-03-18 01:41:17 -0400 |
---|---|---|
committer | Chris Dyer <redpony@gmail.com> | 2014-03-18 01:41:17 -0400 |
commit | 606e3e38b8a830dbbe65963ebf6c5ce7866b7800 (patch) | |
tree | 332cec5e0b4c8e3b8d6cc0d631fe5d5815f088f6 /utils/star.h | |
parent | cc87bfed0697583b7c11243913254dde3c0047d4 (diff) |
star function
Diffstat (limited to 'utils/star.h')
-rw-r--r-- | utils/star.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/utils/star.h b/utils/star.h new file mode 100644 index 00000000..3295112c --- /dev/null +++ b/utils/star.h @@ -0,0 +1,12 @@ +#ifndef _STAR_H_ +#define _STAR_H_ + +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); +} + +#endif |