Don't change global FPU state during round-half-to-even (#5376)

* Don't change global FPU state

* Handle infinity properly
This commit is contained in:
Tiago Koji Castro Shibata 2020-10-13 20:10:33 -07:00 committed by GitHub
parent 67315d8ae0
commit fabe02ddc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,9 +43,11 @@ void QGemm(
concurrency::ThreadPool* thread_pool);
inline float RoundHalfToEven(float input) {
std::fesetround(FE_TONEAREST);
auto result = std::nearbyintf(input);
return result;
if (!std::isfinite(input)) {
return input;
}
// std::remainder returns x - n, where n is the integral value nearest to x. When |x - n| = 0.5, n is chosen to be even
return input - std::remainderf(input, 1.f);
}
} // namespace onnxruntime