Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!hp-pcd!hpcvia!brianh From: brianh@hpcvia.CV.HP.COM (brian_helterline) Newsgroups: comp.lang.c Subject: Re: Assinging values to type float Message-ID: <31530016@hpcvia.CV.HP.COM> Date: 29 Aug 90 14:49:56 GMT References: <90240.003415RHMCSUPV@MIAMIU.BITNET> Organization: Hewlett-Packard Co., Corvallis, Oregon Lines: 41 volpe@underdog.crd.ge.com (Christopher R Volpe) writes: -In article <667.26da7736@iccgcc.decnet.ab.com>, -browns@iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) writes: -|>In article <90240.003415RHMCSUPV@MIAMIU.BITNET>, -RHMCSUPV@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@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 */