Warning about integer divisions in float expressions
Thomas Holenstein
thomas@hex.ch
Thu Jul 27 08:21:00 GMT 2000
Hello,
I am just to stupid. Today, I searched another 2 hours a bug because
I wrote a nice little thing like that in a C++ program:
double x = 1 / 2 / M_PI;
I just hate this integer division. After being a bit angry about it,
I thought that gcc might warn about such an error.
I thought about a rule like that:
If an integer division occurs in an expression which is later
converted into a float or double, gcc emits a warning. Meaning:
int k = (int)(5 / 4 * M_PI);
or
double k = 5 / 4;
would emit a warning.
but
int k = 5 / 4;
won't
The reasoning behind this is, that if someone wants
double d = k / l * 2.5;
where k and l are ints, he probably should write
int tmp = k / l;
double d = tmp * 2.5;
anyhow, because the other is very unreadable IMHO.
Could you please consider this?
Thomas
--
Thomas Holenstein
thomas@hex.ch
More information about the Gcc
mailing list