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

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Traps in floating point code
From: Mike Rawes (mike_rawes_AT_yahoo.co.uk)
Date: Wed Jun 30 2004 - 18:37:59 EEST


--- Pete Bessman <ninjadroid_AT_gazuga.net> wrote:
> At Mon, 28 Jun 2004 19:56:50 +1000,
> Erik de Castro Lopo wrote:
> >
> > double fractional = 0.0, increment = 0.1;
> > int integer = 0;
> >
> > for (;;)
> > {
> > /* Bunch of other code. */
> >
> > fractional += increment ;
> > integer += lrint (floor (fractional));
> > fractional -= floor (fractional);
> > }
>
> I don't understand this lrint (floor ()) stuff. floor() returns a
> truncated integer value, so what's the point of calling lrint() on
> that?

The lrint converts the float value to an int (a lot) faster than a simple cast.

The floor is to get around the rounding rule used by the FPU when the float
value is exactly halfway. It rounds to even numbers, at least it does on an
AthlonXP:

lrintf (1.5) = 2
lrintf (2.5) = 2
lrintf (3.5) = 4
lrintf (4.5) = 4 etc.

which is a royal pain if you use that int for something like a table lookup.

-
Myk

        
        
                
___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many all-new ways to express yourself http://uk.messenger.yahoo.com


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Wed Jun 30 2004 - 18:30:55 EEST