|
-
April 10th, 1999, 01:55 AM
#1
m_floatValue = m_nValue * 0.5 >> Warning!
float m_floatValue;
int m_nValue = 5;
m_floatValue = m_nValue * .5 ; // it give warning message.
: warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
I am not dealing with 'double' at all, and the operation I am doing is quite reasonable. Why does the compiler give this error and how to correct it.
-
April 10th, 1999, 04:48 AM
#2
Re: m_floatValue = m_nValue * 0.5 >> Warning!
You may not be dealing with "double", but the
compiler converts the 0.5 to double. One of the
things that you should be aware of are the type
conversions that C or C++ has to do with
intermediate values.
You probably need to cast the 0.5 to float (and
maybe the m_nValue also).
Regards,
Paul McKenzie
-
April 10th, 1999, 11:38 AM
#3
Re: m_floatValue = m_nValue * 0.5 >> Warning!
The compiler believes that the .5 is a double, without having to use a cast like (float).5, you may use 0.5F:
m_floatValue = m_nValue * 0.5F;
Rail
Recording Engineer/Software Developer
Rail Jon Rogut Software
[email protected]
http://home.earthlink.net/~railro/
-
April 12th, 1999, 06:27 AM
#4
Re: m_floatValue = m_nValue * 0.5 >> Warning!
float m_floatValue;
int m_nValue = 5;
m_floatValue = m_nValue * (float).5 ; // should do the trick
Since float is of lower precision than double (and the compiler assumes _all_ decimal literals are double) it is warning you.
It won't matter for most purposes, but if the software you're authoring is to control nuclear or surgical equipment (for example) it may be important.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|