Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31855 > unrolled thread
| Started by | Marcel Mueller <news.5.maazl@spamgourmet.org> |
|---|---|
| First post | 2015-06-26 09:17 +0200 |
| Last post | 2015-06-29 13:58 -0400 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: elementary loops Marcel Mueller <news.5.maazl@spamgourmet.org> - 2015-06-26 09:17 +0200
Re: elementary loops Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> - 2015-06-26 09:26 +0000
Re: elementary loops Marcel Mueller <news.5.maazl@spamgourmet.org> - 2015-06-26 13:39 +0200
Re: elementary loops Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-06-26 08:26 -0400
Re: elementary loops Arne Vajhøj <arne@vajhoej.dk> - 2015-06-28 20:12 -0400
Re: elementary loops Marcel Mueller <news.5.maazl@spamgourmet.org> - 2015-06-29 19:50 +0200
Re: elementary loops Arne Vajhøj <arne@vajhoej.dk> - 2015-06-29 13:58 -0400
| From | Marcel Mueller <news.5.maazl@spamgourmet.org> |
|---|---|
| Date | 2015-06-26 09:17 +0200 |
| Subject | Re: elementary loops |
| Message-ID | <mmiu9s$pa$1@gwaiyur.mb-net.net> |
On 22.06.15 18.15, Stefan Ram wrote:
> public class Main
> { public static void main( final java.lang.String[] args )
> { short i = -1;
> int j = -1;
> for( int k = 0; k < 65; ++k ){ i >>>= 1; j <<= 32; }
The result of j<<=32 is a no-op and i>>>=1 is unsigned and should become
zero.
Marcel
[toc] | [next] | [standalone]
| From | Andreas Leitgeb <avl@auth.logic.tuwien.ac.at> |
|---|---|
| Date | 2015-06-26 09:26 +0000 |
| Message-ID | <slrnmoq6pg.uoi.avl@login.logic.tuwien.ac.at> |
| In reply to | #31855 |
Marcel Mueller <news.5.maazl@spamgourmet.org> wrote:
> On 22.06.15 18.15, Stefan Ram wrote:
>> public class Main
>> { public static void main( final java.lang.String[] args )
>> { short i = -1;
>> int j = -1;
>> for( int k = 0; k < 65; ++k ){ i >>>= 1; j <<= 32; }
> The result of j<<=32 is a no-op and i>>>=1 is unsigned and should become
> zero.
The short i is promoted to int, then the MSB ("sign"-bit) zeroed,
then converted back to short, where it's still -1
[toc] | [prev] | [next] | [standalone]
| From | Marcel Mueller <news.5.maazl@spamgourmet.org> |
|---|---|
| Date | 2015-06-26 13:39 +0200 |
| Message-ID | <mmjdme$543$1@gwaiyur.mb-net.net> |
| In reply to | #31856 |
On 26.06.15 11.26, Andreas Leitgeb wrote:
>>> { public static void main( final java.lang.String[] args )
>>> { short i = -1;
>>> int j = -1;
>>> for( int k = 0; k < 65; ++k ){ i >>>= 1; j <<= 32; }
>
> The short i is promoted to int, then the MSB ("sign"-bit) zeroed,
> then converted back to short, where it's still -1
In this case the >>> operator is meaningless for short int and there is
no option to perform this operation except for emulating the behavior by
other bit functions or types. The same applies to byte as well.
Of course, this is only another side effect of the missing unsigned types.
Is this guaranteed by the language or just implementation defined?
Marcel
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-06-26 08:26 -0400 |
| Message-ID | <mmjgbb$him$1@dont-email.me> |
| In reply to | #31857 |
On 6/26/2015 7:39 AM, Marcel Mueller wrote:
> On 26.06.15 11.26, Andreas Leitgeb wrote:
>>>> { public static void main( final java.lang.String[] args )
>>>> { short i = -1;
>>>> int j = -1;
>>>> for( int k = 0; k < 65; ++k ){ i >>>= 1; j <<= 32; }
>>
>> The short i is promoted to int, then the MSB ("sign"-bit) zeroed,
>> then converted back to short, where it's still -1
>
> In this case the >>> operator is meaningless for short int and there is
> no option to perform this operation except for emulating the behavior by
> other bit functions or types. The same applies to byte as well.
> Of course, this is only another side effect of the missing unsigned types.
> Is this guaranteed by the language or just implementation defined?
The former. The relevant bits of the Java Language Specification
<http://docs.oracle.com/javase/specs/jls/se8/html/index.html> are
- 15.26.2 "Compound Assignment Operators"
- 15.19 "Shift Operators"
- 5.6.1 "Unary Numeric Promotion"
- 5.1.2 "Widening Primitive Conversion"
- 15.16 "Cast Expressions" (implied by 15.26.2)
- 5.1.3 "Narrowing Primitive Conversion"
--
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-06-28 20:12 -0400 |
| Message-ID | <55908d68$0$291$14726298@news.sunsite.dk> |
| In reply to | #31857 |
On 6/26/2015 7:39 AM, Marcel Mueller wrote:
> On 26.06.15 11.26, Andreas Leitgeb wrote:
>>>> { public static void main( final java.lang.String[] args )
>>>> { short i = -1;
>>>> int j = -1;
>>>> for( int k = 0; k < 65; ++k ){ i >>>= 1; j <<= 32; }
>>
>> The short i is promoted to int, then the MSB ("sign"-bit) zeroed,
>> then converted back to short, where it's still -1
>
> In this case the >>> operator is meaningless for short int and there is
> no option to perform this operation except for emulating the behavior by
> other bit functions or types. The same applies to byte as well.
> Of course, this is only another side effect of the missing unsigned types.
> Is this guaranteed by the language or just implementation defined?
There is (luckily) very little implementation specific
and undefined in the Java language.
Arne
[toc] | [prev] | [next] | [standalone]
| From | Marcel Mueller <news.5.maazl@spamgourmet.org> |
|---|---|
| Date | 2015-06-29 19:50 +0200 |
| Message-ID | <mms0gn$l17$1@gwaiyur.mb-net.net> |
| In reply to | #31867 |
On 29.06.15 02.12, Arne Vajhøj wrote: > There is (luckily) very little implementation specific > and undefined in the Java language. Oh, race conditions work pretty well in Java. Like in many other languages too, of course. Marcel
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-06-29 13:58 -0400 |
| Message-ID | <55918738$0$295$14726298@news.sunsite.dk> |
| In reply to | #31875 |
On 6/29/2015 1:50 PM, Marcel Mueller wrote: > On 29.06.15 02.12, Arne Vajhøj wrote: >> There is (luckily) very little implementation specific >> and undefined in the Java language. > > Oh, race conditions work pretty well in Java. Like in many other > languages too, of course. That is true. But still way less of those things than f.ex. C. Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web