Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26516

Re: Possible loss of precision

Date 2013-11-15 20:48 -0800
From Patricia Shanahan <pats@acm.org>
Newsgroups comp.lang.java.programmer
Subject Re: Possible loss of precision
References <loss-20131113231933@ram.dialup.fu-berlin.de> <87txfe22o1.fsf@golem.phantasia.org> <kkla89tv4vb3c60ao7qkj2hr3kd0ims4gc@4ax.com> <87txfded5c.fsf@golem.phantasia.org>
Message-ID <1cydnYUCtYikZBvPnZ2dnUVZ_umdnZ2d@earthlink.com> (permalink)

Show all headers | View raw


On 11/15/2013 10:24 AM, Michael Jung wrote:
> Gene Wirchenko <genew@telus.net> writes:
>> On Thu, 14 Nov 2013 20:39:42 +0100, Michael Jung
>> <miju@golem.phantasia.org> 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.

I think the difference is that there is a cast-free way of initializing 
an int to the value 2.

On the other hand, without the special narrowing rule for initializers, 
there would be no cast-free way of initializing a byte with the value 2.

Patricia

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Possible loss of precision Michael Jung <miju@golem.phantasia.org> - 2013-11-14 20:39 +0100
  Re: Possible loss of precision Gene Wirchenko <genew@telus.net> - 2013-11-14 15:03 -0800
    Re: Possible loss of precision Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-11-14 18:31 -0500
      Re: Possible loss of precision Joerg Meier <joergmmeier@arcor.de> - 2013-11-15 00:55 +0100
      Re: Possible loss of precision Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-11-14 20:19 -0500
        Re: Possible loss of precision taqmcg@gmail.com - 2013-11-15 07:01 -0800
        Re: Possible loss of precision Martin Gregorie <martin@address-in-sig.invalid> - 2013-11-15 21:36 +0000
    Re: Possible loss of precision Michael Jung <miju@golem.phantasia.org> - 2013-11-15 19:24 +0100
      Re: Possible loss of precision Patricia Shanahan <pats@acm.org> - 2013-11-15 20:48 -0800
        Re: Possible loss of precision Michael Jung <miju@golem.phantasia.org> - 2013-11-17 13:28 +0100
          Re: Possible loss of precision Patricia Shanahan <pats@acm.org> - 2013-11-17 08:05 -0800

csiph-web