template<typename T> bool isfinite(T t) { return t == t && t != std::numeric_limits<T>::infinity() && t != -std::numeric_limits<T>::infinity(); }