Subject: Re: [linux-audio-dev] Traps in floating point code
From: Jens M Andreasen (jens.andreasen_AT_chello.se)
Date: Wed Jun 30 2004 - 20:00:21 EEST
On tis, 2004-06-29 at 17:15, Steve Harris wrote:
> On Tue, Jun 29, 2004 at 10:19:32AM +0200, Benno Senoner wrote:
> > for (;;)
> > {
> > /* Bunch of other code. */
> >
> > fullindex += increment;
> > integer = lrintf(fullindex);
> > fractional = fullindex - integer;
>
> I dont think this is right, fractional will be [-0.5, 0.5], rather than
> [0,1] which is more noirmal as lrintf() rounds to the nearest.
>
> I think you should be using lrintf(floor(x)) or (int)x.
Why not just use modf?
double fullindex, increment, integer, fraction;
// int i;
fullindex += increment;
fraction = modf(fullindex, &integer);
// i = integer;
C99 have float and long double versions as well.
>
> - Steve
This archive was generated by hypermail 2b28 : Wed Jun 30 2004 - 19:50:46 EEST