2 ms·
> nan is equal to itself > The result of division by zero is nan This is all a mistake!! IEEE put a lot of thought into making NaN != NaN and having Inf and N
by dmitrygr 1y ago
> nan is equal to itself
> The result of division by zero is nan
This is all a mistake!! IEEE put a lot of thought into making NaN != NaN and having Inf and NaN be separate things. As it stands 1e130 / 1e-10 == 5 / 0 == 0 / 0. Should that be the case? No. Why might this come up accidentally without you noting this? Imagine each of the following funcs is in a separate module written by separate people. frob() will be called errorneously with DEC64 and will not with float or double
int main(int, char**) {
//[...]
rateOfThisThing = getRateOfThing1();
rateOfThatThing = getRateOfThing2();
if (rateOfThisThing == rateOfThatThing) {
frob();
}
//[...]
}
void frob(void) {
//[...]
}
DEC64 getRateOfThing1(void) {
return calculateRate(mThingOneProgress, getTime() - mTimeWhenThing1started);
}
DEC64 getRateOfThing3(void) {
return calculateRate(mThingTwoDone, getThingTwoRuningLength());
}
DEC64 calculateRate(DEC64 done, DEC64 time) {
return (done + time / 2) / time
}