[PATCH] Don't calculate with NaN when on 100% o2
Dirk Hohndel
dirk at hohndel.org
Mon Mar 17 20:39:41 PDT 2014
On Mon, 2014-03-17 at 13:05 -0700, Linus Torvalds wrote:
> 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);
The triple '=' is something I know from javascript :-)
I really don't want Anton's patch. Linus hasn't submitted a better
patch. I could just take both of them and merge them.
The choices, the choices...
I think I'll do my own patch without using the javascript extension to
C :-)
/D
More information about the subsurface
mailing list