[linux-audio-dev] Traps in floating point code

Erik de Castro Lopo erikd-lad at mega-nerd.com
Tue Jun 29 20:56:17 UTC 2004


On Tue, 29 Jun 2004 10:19:32 +0200
Benno Senoner <sbenno at gardena.net> wrote:

> In LinuxSampler we do
> 
>   double increment;
>   double fullindex;
>   int integer;
>   double fractional;
>   for (;;)
>   {
>     /* Bunch of other code. */
> 
>     fullindex += increment;
>     integer = lrintf(fullindex);
>     fractional = fullindex - integer;
>   }

Have you tried compiling your code with gcc-3.4? Do you have a test suite
that will pick up if the above construct turns out wrong?

Lets say that after the addition of increment, the value of fullindex
in the 80 bit internal representation is 1.99999999999999999999999.
Pass that number through lrint and you get 2 and subtract 2 from the
80 bit internal representation and you get -0.00000000000000000000001
which is excatly the sort of problem I was trying to avoid.

> I did not benchmark the above code against yours but I think it should 
> be faster.

I value correct-ness above speed :-).

> (plus instead of lrintf() we use an asm FISTL macro which is a bit 
> faster (around 10% IIRC).

lrintf() is portable (ISO C99 standard), FISTL is not.

Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam at mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"If you need a piece of paper and a pen to explain it,
then its not bleedin' obvious" -- Erik's First Law



More information about the Linux-audio-dev mailing list