Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26504
| 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 <miju@golem.phantasia.org> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Possible loss of precision |
| Date | Thu, 14 Nov 2013 20:39:42 +0100 |
| Organization | albasani.net |
| Lines | 20 |
| Message-ID | <87txfe22o1.fsf@golem.phantasia.org> (permalink) |
| References | <loss-20131113231933@ram.dialup.fu-berlin.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=iso-8859-1 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.albasani.net c1UcvKIZA7ocmc6uOfo/QD+VoikDPl2gb+2byyoXXJ59paRR86RyzbMzqo4pHdAr6gyWmpXFXYldundKZf71Y+Kpa5Myenvz2nvpjXYPsU7llWP0MeHy7woRBbJJenJ8 |
| NNTP-Posting-Date | Thu, 14 Nov 2013 19:39:43 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="9PIzizP/GbiSiG0sGk9zdpZtJ6283mBrFUi9f3YF+Bw3sa8YIFZ9plHbPI/VvruwQnlaZII9h4YlaW9OtgvJ60dQ7Xvpt6tFFbjMqQbOfeCZxTZVmAPzbJo9e0BG69Ct"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:qvCG+USz2jPbpNwdDUIAZq+bnw8= sha1:YGSulu4qRnagDp2bFPBRC83w/rc= |
| Xref | csiph.com comp.lang.java.programmer:26504 |
Show key headers only | View raw
ram@zedat.fu-berlin.de (Stefan Ram) writes: > char x = 'C' + 1; > x = x + 1; > in a block, one gets an error message > »possible loss of precision« > for »x = x + 1«. Ok, fair enough: »x + 1« has type »int«, > and precision is lost when assigning this to the variable x > of type char. > I was somewhat surprised, though, that »char x = 'C' + 1;« > does not yield an error, even though the type of »'C' + 1« > is int, too. Possibly, this time, the compiler can figure > out that the actual value still fits into a char. > 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.
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll 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