Fallback rint() does not avoid signed integer overflow (undefined behaviour) or INF
Submitted by Morten Welinder
Link to original bug (#696604)
Description
The fallback rint implementation has problems:
a = (int) ceil (x);
This will overflow for large x. And all large x will get there because all large x are even integers with x == x+0.5.
Instead, something like
double y = floor (x + 0.5) / 2;
if (y == floor (y)) ...;
If one weren't concerned with portability there is also fmod.
(And someone needs to think about Inf.)
Version: 3.22.x