Electronics > Microcontrollers

Precision of operations using #define

<< < (4/4)

SiliconWizard:
If you're using integer calculations, be they compile-time or run-time, as long as you follow a few basic rules (promotion and literal suffixes), results will be exact. No need to overthink it, especially for things as simple as baud rate calculation. If you are afraid of rounding errors, just use integers only.

Only in rare cases where you'd need very large integers for representing fractional frequencies, for instance, and which could lead to overflow when multiplied, should you be careful. In any case, a quick analysis of the calculation should tell you what's OK and what is not.

Navigation

[0] Message Index

[*] Previous page

There was an error while thanking
Thanking...
Go to full version