Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 30 May 2011 14:02:38 -0500 From: Pete Becker Organization: Roundhouse Consulting, Ltd. Newsgroups: comp.lang.c++ Date: Mon, 30 May 2011 09:02:38 -1000 Message-ID: <201105300902384725-pete@versatilecodingcom> References: <94gjh4Fr2iU9@mid.individual.net> <4de3835d$0$2833$7b1e8fa0@news.nbl.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: implicit promotion User-Agent: Unison/2.1.4 Lines: 54 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-i0TfjA3FpwRSm/spBNq8HonG7C1+e7h2WKk/DhbJZKcAn4zcN4EQ82mB1oKDaSxfo4US1v7oVMjJ8Ok!vv3xdPe/S7aueequamw7JkwApdsT9T0NihkMUnOLRh5YewO46WRTKD58PUmRCeYM8NQ5aw== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3562 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:5839 On 2011-05-30 08:39:59 -1000, Öö Tiib said: > On May 30, 6:17 pm, Paavo Helde wrote: >> Juha Nieminen wrote >> innews:4de3835d$0$2833$7b1e8fa0@news.nbl.fi: >> >> >> >> >> >>> Paavo Helde wrote: >>>>> If you write >> >>>>> float tot = (float)sum/tally->size(); >> >>>>> you then have a float divided by an int, 1.5. >> >>>> Yes, for getting floating-point division one needs to cast only one >>>> operand to a floating-point type, the other would be cast to the type >>>> of the first automatically. In the original line from OP both >>>> operands were cast, possibly because the original author liked >>>> symmetry or clarity. >> >>>   Actually, if a float is divided by an int, aren't both of them cast >>> to double first? (Not that it probably makes any difference in >>> practice, but just pointing out.) >> >> As far as I can see from 5/9, no, float-int are converted to float-float. >> There is a thingie called "floating-point promotion" which promotes to >> double, but this is not mentioned in this section (unlike integral >> promotion) and seems to be used only for converting floats passed as >> va_arg arguments. > > My confusion is about the 5/10: > The values of the floating operands and the results of floating > expressions may be represented in greater precision and range than > that required by the type; the types are not changed thereby. > > I read that the implementation may use double or long double under the > hood whereonly it wants in floating point arithmetics as long it > pretends that things still are "float" to the developer. That allows things like the Intel math processor, which does all floating-point math with 80-bit values (unless you turn this off, which makes it much slower), then converts them to the target type (32-bit float, 64-bit double). But that affects the value of the result (down in the noise bits), not its type. -- Pete Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The Standard C++ Library Extensions: a Tutorial and Reference (www.petebecker.com/tr1book)