float format
-
hello, I have the following problem, float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout=(0.5/5)*(queueinput-60); return (queueout); } When I execute it, it give me the warning: "=": conversion from 'double' to 'float', possible loss of data Does anyone know what's wrong inside it? THX!!! :):):)
-
hello, I have the following problem, float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout=(0.5/5)*(queueinput-60); return (queueout); } When I execute it, it give me the warning: "=": conversion from 'double' to 'float', possible loss of data Does anyone know what's wrong inside it? THX!!! :):):)
wong1907 wrote:
_queueout=(0.5/5)*(queueinput-60);_
(0.5/5) evaluates to a double-precision value, thus when multiplied bu your float, the result is a double. I usually use doubles and forget about float (I do numerical analyses that may be significant out to 20 decimal places or so). If you are set on using the smaller float, try:float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout = static_cast < float > ((0.5/5)*(queueinput-60)); return (queueout); }
Nitron _________________________________________-- message sent on 100% recycled electrons. -
hello, I have the following problem, float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout=(0.5/5)*(queueinput-60); return (queueout); } When I execute it, it give me the warning: "=": conversion from 'double' to 'float', possible loss of data Does anyone know what's wrong inside it? THX!!! :):):)
Numbers are double, by default. To avoid this warning, you can either disable it (#pragma warning...), or more carefully tell the compiler you are using floats : 0.5 --> 0.5f, 5 --> 5.0f, ...
How low can you go ?
(MS retrof_u_ck) -
hello, I have the following problem, float medium(float queueinput) { float queueout; if ((queueinput>60)&&(queueinput<65)) queueout=(0.5/5)*(queueinput-60); return (queueout); } When I execute it, it give me the warning: "=": conversion from 'double' to 'float', possible loss of data Does anyone know what's wrong inside it? THX!!! :):):)
Any reason why you are using
float
instead ofdouble
?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb