SV: [Icc-avr] Calculations

Steven Lose sl at ecpower.dk
Mon Jan 7 06:49:59 PST 2008


Hi.

 

0/(16L*baudrate) is 0

0 - 1 is 65535 when int is used.

 

Med venlig hilsen / Best regards / mit freundlichen Grüßen

EC POWER A/S

Steven Lose

Software Ingeniør

Tlf.: +45 87434100

Direkte tlf. +45 58286608

Email: sl at ecpower.dk <blocked::mailto:bsl at ecpower.dk> 

www.ecpower.dk

________________________________

Fra: icc-avr-bounces at imagecraft.com [mailto:icc-avr-bounces at imagecraft.com] På vegne af Bengt Ragnemalm
Sendt: 7. januar 2008 15:29
Til: ICC-AVR discussion list
Emne: [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/a2b84a3d/attachment-0001.html


More information about the Icc-avr mailing list