[James Morris]
On 15 July 2010 18:23, Harry Van Haaren
<harryhaaren(a)gmail.com> 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