Community
Participate
Working Groups
One of the most common bugs we are facing is when we devide two integer values (int or Integer) and assigning the result to a double variable/field, we sometimes forget to ensure it is done as a floating point operation by using casting ( double x = (double) intA / intB ). Uusually if one does not need floating point precision it makes no sense to assign the result to a double variable. Thus such an assignment without an explicit cast to double is most of the time not intensionally and leads to bug. It would be of a extrem great help if eclipse could add a warning/error in such cases. Thanks in advance, Stefan C. Ionescu
Do you mean to say people would assume the result of 10/3 is 3.333.. but in reality would only be 3.0? I am not sure if everyone will like an additional warning in their existing code. Perhaps as an info. Personally, I am not keen, though. Anybody things otherwise?
(In reply to Jay Arthanareeswaran from comment #1) > Do you mean to say people would assume the result of 10/3 is 3.333.. but in > reality would only be 3.0? If you assign the result to a double variable, yes of course. Why would you assign it to a floating point precision variable if you intend to stay in integer precision? > > I am not sure if everyone will like an additional warning in their existing > code. Perhaps as an info. Personally, I am not keen, though. Beside the fact that the warnings/errors/info are configurable in eclipse, i wouldn't care if people like it. It is causing wrong calculations. > > Anybody things otherwise? If others don't like this or don't care make it default disabled but please allow to enable such a warning. This is source number one of errors for us.