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."


_______________________________________________
AVR-GCC-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to