Solved Suppression of Implicit Conversion warnings
-
I am running the current version of QtCreator on a Mac with the current version of Xcode.
When I compile a program with the following line,
int x = round(1.1);
I receive a warning that states:
"implicit conversion turns floating-point number to integer; 'double' to 'int'"
How may I suppress such warnings?
Thank you.
Hoyt
-
Hi,
What about using
std::rint
? -
SGaist,
The line
x = std::rint(1.1);
generates the same warning.
"implicit conversion turns floating-point number into integer: 'double' to 'int'"
I would like to turn off all "implicit conversion" warnings.
Hoyt
-
@Hoyt
Hi
Why not use
std::lround(); ( Lround)
If you want to round to nearest int.Google says you can hide these warnings you can switch “implicit conversion to 32 bit type” to no in your build settings. Might only affect other converts and not double to int truncating.
Not that i recommend it as it will also hide the cases where it does matter :) -
mrjj,
I receive another implicit conversion with std::lround()
I can solve the problem by using static_cast<int> . I guess that I will utilize casting to eliminate the warnings.
Hoyt
-
@Hoyt
Hi
Ok which complication ?
(just to know)
yes, you can cast it and it should accept that.
I just thought you wanted to round the value not cap it.
so 1.0 and 1.9 both be 1. -
@Hoyt
you should combinestatic_cast<int>
and round, otherwise you'll run into floating point issues. Remember:static_cast<int>(0.8 * 10) = 7 //!!!
int i = static_cast<int>(round(value));