Quote:
|
Originally Posted by steven114
Might I point out that 150/100 will evaluate to 1, not 1.5... there is no way to store a floating point number in an integer. You can hack around it by storing an exponent, but I don't believe setting myInt to 150/100 will store 1.5...
|
#define's don't evaluate expressions.
You don't evaluate (150/100). You evaluate (x * 150 / 100).
To get a floating point effect you do all your multiplication first, then all your division.
In integer math,e.g.,
x = 150/100 * 100 = 100
but
x = 100 * 150 / 100 = 150
Just be careful to type cast the expression to the largest size you need, e.g., using all
char for the above will return an incorrect result.