FIXUP WITH 94b64b1

Clear up the mess with undefined behaviour, every calculation with NaN
and infinity is defined in IEEE. Not goind too much in detail, there
are too many special cases, but roughly doing it.