[Icc-avr] Calculations
Glenn Greig
ggreig at rossvideo.com
Mon Jan 7 07:03:37 PST 2008
No compiler error, Bengt.
Clearly the correct answer for temp2 is -1 (signed), which is 65535 (unsigned).
Glenn
-----Original Message-----
From: icc-avr-bounces at imagecraft.com [mailto:icc-avr-bounces at imagecraft.com]On Behalf Of Bengt Ragnemalm
Sent: January 7, 2008 9:29 AM
To: ICC-AVR discussion list
Subject: [Icc-avr] Calculations
Hi!
I have spent some of my spare time during Christmas solving some strange problems I have had with a design. My problems was something completely different but I ended up with this:
- I have found a calculation that may be a compiler error.
This is my test code, baudrate is 38400:
#define F_CPU 7372800
temp2 = F_CPU/(16L*baudrate)-1; // Normal calculation, result OK
temp2 = 0/(16L*baudrate)-1; // Results into 65535
I guess that the last calculation error is because of some rounding problem but obviously the correct answer is 0.
/Bengt
________________________________________________________________
Bengt Ragnemalm Tel +46 13 22 24 97
Research engineer FAX: +46 13 10 19 02
Linköpings Universitet <mailto:bengt.ragnemalm at imt.liu.se> mailto:bengt.ragnemalm at imt.liu.se
Inst. för Medicinsk Teknik Internet: <http://www.imt.liu.se/> http://www.imt.liu.se
S-581 85 Linköping SWEDEN
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20080107/6b4fe4bd/attachment.html
More information about the Icc-avr
mailing list