Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail From: Michael Jung Newsgroups: comp.lang.java.programmer Subject: Re: Possible loss of precision Date: Fri, 15 Nov 2013 19:24:47 +0100 Organization: albasani.net Lines: 18 Message-ID: <87txfded5c.fsf@golem.phantasia.org> References: <87txfe22o1.fsf@golem.phantasia.org> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.albasani.net uMSMcNlM43IKVstp8PjVFz+AmcYnQYMorZhS8AQIsg1plReU3IIP1ZjSohmYPRqEg8n30VKfuDqs7oNFPJOecg== NNTP-Posting-Date: Fri, 15 Nov 2013 18:24:48 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="V++yFAIAh/RosDkghmK43UL2GfA0kpFLknv0UYa3/dyCypIkTUAkdrQAUq09qX7WXZxrx6u31xwgJTtcmdRLWwagxhffFaeiUw2+aPRoJMTvvEwjI3BuDGPPgdDOkcF+"; mail-complaints-to="abuse@albasani.net" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:qpY2E0fD+gJ8rSNMd96fF6ZoLao= sha1:RnIhgBoaBcrP2U1NqEHH8Q8rI1U= Xref: csiph.com comp.lang.java.programmer:26513 Gene Wirchenko writes: > On Thu, 14 Nov 2013 20:39:42 +0100, Michael Jung > wrote: >>ram@zedat.fu-berlin.de (Stefan Ram) writes: [...] >>> But then, »int i = 2.0;« gives an error, even though the >>> compiler should see that »2.0« can be represented as an int. >>You are right that x+1 is "promoted" to int and the second assignment >>fails. In the other cases the compiler will follow JLS 15.28 => 5.2. >>This concerns constant expressions first and the second allows a >>narrowing in rare cases, of which the first line is one but the >>"int i = 2.0" isn't. > Why isn't it though? Since compile-time constant expressions are FP-strict and could be done, I guess it was seen as pathological and not worth the effort. Michael