Reputation: 4783
My code:
#inlcude <math.h>
#include "draw.h" /*int draw(int x, int y)*/
draw(rintf(10 * x), rintf(8 * y));
I get this warning: Conversion to ‘int’ from ‘float’ may alter its value.
I can't change draw
to float, since I need it to draw points. So rounding is inevitable. Any ideas?
Upvotes: 2
Views: 3692
Reputation: 42139
The return type of rintf
is float
which produces the warning. You can either explicitly cast to int
to suppress the warning (i.e., (int) rintf(10 * x)
, or you could use another way of rounding (e.g., if the values are known to be non-negative, (int) (10.0f * x + 0.5f)
) or lrint
(preferably from tgmath.h
), although it returns a long
which may cause another warning depending on your compiler and settings.
Upvotes: 1