Assinging values to type float

brian_helterline brianh at hpcvia.CV.HP.COM
Thu Aug 30 00:49:56 AEST 1990


volpe at underdog.crd.ge.com (Christopher R Volpe) writes: 
-In article <667.26da7736 at iccgcc.decnet.ab.com>,
-browns at iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) writes:
-|>In article <90240.003415RHMCSUPV at MIAMIU.BITNET>,
-RHMCSUPV at MIAMIU.BITNET (Douglas M. MacFarlane) writes:
-|>>  
-|>> float fValue ;     /* define fValue as a floating point variable  */
-|>>  
-|>> other lines
-|>>  
-|>> fValue = 35 ;     /* produces a Data Conversion warning at compile time */
-|>>  
-|>>  
-|>> Whasss Happening ????
-|>>  
-|>> Douglas M. MacFarlane
-|>> rhmcsupv at miamiu.acs.muohio.edu
-|>
-|>
-|>From the Microsoft C 5.1 user's guide, page 275:
-|>
-|>C4051  data conversion
-|>       Two data items in an expression had different types, causing
-|>       the type of one item to be converted.
-|>
-|>"fValue" is a float.  "35" is an int.  The compiler converted an int to a
-|>float for you.  If you wanted a float, it thinks, you'd have written 35.0.
-|>(Of course 35.0 is actually a double, as are all floating-point constants,
-|>but that's another story.)

-Ok, so which is it? Is the compiler complaining about the int-to-double
-conversion for not writing 35.0? Or is it complaining about the
-double-to-float conversion resulting in possible loss of precision?
-Does the warning go away if you write "fValue=35.0;" or do you
-need to write "fValue = (float) 35.0"?                                     

	MSC is complainting about the double-to-float conversion because
	there is loss of precision and not all doubles will fit into a
	float.  On the other hand, all ints will fit into floats.

	The only way to quiet MSC is fValue = (float) 35 /* or 35.0 */



More information about the Comp.lang.c mailing list