[linux-audio-dev] Traps in floating point code
Jens M Andreasen
jens.andreasen at chello.se
Wed Jun 30 17:00:21 UTC 2004
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
More information about the Linux-audio-dev
mailing list