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: Pete Bessman (ninjadroid_AT_gazuga.net)
Date: Wed Jun 30 2004 - 22:25:53 EEST


At Wed, 30 Jun 2004 16:37:59 +0100 (BST),
Mike Rawes wrote:
>
> --- 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.

Ah. Now I get to find all the places in my code that can benefit from
that. If you assign a float value into an int variable, is that an
implicit 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:

Good to know, thanks for the tip. Although, just using lrintf(val)
would be wrong anyway because it would round up if fmod(val, 1.0) >
0.5, right?

-Pete

www.gazuga.net


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 - 22:17:18 EEST