Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

warning C4244: 'return': conversion from 'double' to 'float', possible loss of data

Why do I get this compiler warning message on lines 2-6?

warning C4244: ‘return’: conversion from ‘double’ to ‘float’, possible loss of data

inline float SIGN(const double &a, const float &b)
    {return b >= 0 ? (a >= 0 ? a : -a) : (a >= 0 ? -a : a);}
inline float pow (float x, double y) {return pow(double(x),y);}
inline float pow (double x, float y) {return pow(x,double(y));}
inline float atan2 (float x, double y) {return atan2(double(x),y);}
inline float atan2 (double x, float y) {return atan2(x,double(y));}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In C and C++, the float type is lower precision than the double type. You have declared your functions as returning floats, but the functions are working with doubles. The rules of mixing numerical types apply here, and some types get converted, silently, as you combine them.

The results of your functions, as calculated inside them, are doubles which you then return from the functions as floats. The compiler is warning you that it is possible that the value in the double type you are returning from inside your function will not fit in the functions’ return type float properly, and some precision may be lost in the conversion. It does not otherwise explicitly warn you about mixing float and double. But it might if you mixed int and double.

There is little value to using float types on modern (younger than 10 years) desktop or server hardware.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading