This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Warning about integer divisions in float expressions
- To: gcc at gcc dot gnu dot org
- Subject: Warning about integer divisions in float expressions
- From: Thomas Holenstein <thomas at hex dot ch>
- Date: Thu, 27 Jul 2000 17:21:10 +0200 (MET DST)
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