[James Morris]
>On 15 July 2010 18:23, Harry Van Haaren <harryhaaren@email-addr-hidden> wrote:
>> http://en.wikipedia.org/wiki/Denormal_number
>>
>> A nice "quick" fix for these is:
>> if ( number < 0.000000001)
>> number = 0.0;
>>
>> ;-)
>
>Don't forget about negative numbers ;-)
>
>n = ((n > 0.0 && n < 0.000000001) || (n < 0.0 && n > -0.000000001)) ? 0.0 : n;
I can't seem to remember the most sensible numeric limit for this
branching variant of denormal removal -- besides, it obviously depends
on the context in question and the use of floats versus doubles (as
does the use of fabsf versus fabs in what follows) -- but I am quite
positive that the following line, which replaces the above one, is not
only easier to read, but also stands a good chance of executing
quicker on most contemporary CPUs due to the elimination of at least
one branching instruction:
n = fabs(n) < 1e-9 ? 0 : n;
Cheers, Tim
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Fri Jul 16 20:15:30 2010
This archive was generated by hypermail 2.1.8 : Fri Jul 16 2010 - 20:15:30 EEST