#pragma once #include #include #include template inline bool isNaN(T x) { /// To be sure, that this function is zero-cost for non-floating point types. if constexpr (std::is_floating_point_v) return std::isnan(x); else return false; } template inline bool isFinite(T x) { if constexpr (std::is_floating_point_v) return std::isfinite(x); else return true; } template bool canConvertTo(Float64 x) { if constexpr (std::is_floating_point_v) return true; if (!isFinite(x)) return false; if (x > Float64(std::numeric_limits::max()) || x < Float64(std::numeric_limits::lowest())) return false; return true; } template T NaNOrZero() { if constexpr (std::is_floating_point_v) return std::numeric_limits::quiet_NaN(); else return {}; }