3 ms·
> once you try your hands on some serious floating-point, you quickly learn that an expression like x == 0 (or even like x <= 0) is a strong code smell. Yes, s
by acqq 7y ago
> once you try your hands on some serious floating-point, you quickly learn that an expression like x == 0 (or even like x <= 0) is a strong code smell.
Yes, specifically here is that comparison that surely should not be written as such:
template <typename T> T e(T x) {
return x == 0. ? 1. : (exp(x) - 1.)/x;
}
and also:
https://en.cppreference.com/w/cpp/numeric/math/expm1 https://en.cppreference.com/w/cpp/numeric/math/expm1