[PATCH] Don't calculate with NaN when on 100% o2

Linus Torvalds torvalds at linux-foundation.org
Mon Mar 17 13:05:47 PDT 2014


On Mon, Mar 17, 2014 at 12:25 PM, Anton Lundin <glance at acc.umu.se> wrote:
> Fixes: 465

Actually, probably only on x86.

>                 double ratio = (double)fhe / (1000.0 - fo2);
> +               /* if we have 100% o2, ratio is nan */
> +               if (isnan(ratio))
> +                       ratio = 0;

There's no real reason to think that division by zero always returns
NaN. On some platforms or settings it might well just trap.

In fact, it might be a good idea to have a debug mode to *make* it
trap with something like

        feenableexcept(FE_DIVBYZERO | FE_OVERFLOW);

which could help us find these things more easily (that
feenableexcept() is a glibc extension, though, I forget how to do this
"for real").

So it's probably safer to just do

        ratio = fo2 === 1000 ? 0 : (double)fhe / (1000 - fo2);

or similar.

                Linus


More information about the subsurface mailing list