[PD-dev] [PATCH] Avoid crash in vd~ for nan/inf input values
Kjetil Matheussen
k.s.matheussen at gmail.com
Wed Sep 11 20:53:12 CEST 2013
On Tue, Sep 10, 2013 at 8:40 PM, Claude Heiland-Allen
<claude at mathr.co.uk> wrote:
> Hi Kjetil,
>
> In my own code I tend to exploit the incomparibility of NaN.
>
> Instead of:
>
> if (x < lo) x = lo;
> if (x > hi) x = hi;
>
> I write:
>
> if (! (x >= lo)) x = lo;
> if (! (x <= hi)) x = hi;
>
> As any comparison with NaN gives false, the first version will pass NaN
> through unchanged, but the second version will replace NaN with lo.
> Behaviour with finite values and +/-Infinity should remain the same as
> the first version.
>
Hi Claude,
That is a nice solution, but is
"
if (! (x >= lo)) x = lo;
if (! (x <= hi)) x = hi;
"
reallly faster than
"
if(!isfinite(x))
x = 0.0f;
if (x < lo) x = lo;
if (x > hi) x = hi;
"
?
If not, the second option is much clearer.
More information about the Pd-dev
mailing list