|
From: | Paulo Marques |
Subject: | Re: [avr-gcc-list] Operation problem |
Date: | Fri, 10 Aug 2007 12:15:55 +0100 |
User-agent: | Thunderbird 1.5.0.12 (X11/20070509) |
Gerard Marull Paretas wrote:
Hello.
Hi,
When I try to execute this line:currentsong.length=(currentsong.frames * currentsong.samples_per_frame) / currentsong.samples_per_sec;currentsong.length gets no result. However, doing these operations step by step produce the expected results:currentsong.length=currentsong.frames; currentsong.length*=currentsong.samples_per_frame; currentsong.length/=currentsong.samples_per_sec;The second method requires currentsong.length to be a long int (uint32_t), because the multiplication of currentsong.frames by currentsong.samples_per_frame does not fit on an uint16_t.
I think you just answered your own question: if all the variables involved are uint16_t, then that is the precision used for all he expression and it will overflow on the multiplication.
-- Paulo Marques Software Development Department - Grupo PIE, S.A. Phone: +351 252 290600, Fax: +351 252 290601 Web: www.grupopie.com "A tautology is a thing which is tautological."
[Prev in Thread] | Current Thread | [Next in Thread] |