[PD] removing NaN pure-pd

Martin Peach martin.peach at sympatico.ca
Wed Oct 29 20:03:45 CET 2008

Charles Henry wrote:
> > My best guess is that NaN's come from underflow, under normal
> > circumstances.  I wish there would be an easy way to change this
> > behavior via a compiler flag, but I don't think there is.
> >
> > It seems to be a more pervasive problem, and it's unreasonable to
> > expect to add NaN handlers in application code.  Thank the IEEE
> > standards for this gem.
>I did some more searching around to find that someone has written just
>such a handler for underflow here:
>The code uses the sigcontext struct when a floating point exception
>occurs, to set the result to zero, once an underflow is created.
>Underflow traps are enabled by (gcc) compiler flag -mfp-trap-mode=u
>I'm really not sure about how all of this can be applied successfully.
>  Has anyone implemented this kind of handler before?

In the perform routine of sqosc~, I used:
    if (finite(sample))*out++ = sample;
    else *out++ = 0.0;
to get rid of denormals.

For MSW builds that required adding:
#include <float.h> /* for _finite */
#define finite _finite

Seems like the simplest solution to me...


More information about the Pd-list mailing list