Re: Bug in shifting

2018-12-19 Thread Patrick Schluter via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 20:33:43 UTC, Rainer Schuetze wrote: On 14/12/2018 02:56, Steven Schveighoffer wrote: On 12/13/18 7:16 PM, Michelle Long wrote: byte x = 0xF; ulong y = x >> 60; Surely you meant x << 60? As x >> 60 is going to be 0, even with a ulong. It doesn't work as

Re: Bug in shifting

2018-12-18 Thread Rainer Schuetze via Digitalmars-d-learn
On 14/12/2018 02:56, Steven Schveighoffer wrote: > On 12/13/18 7:16 PM, Michelle Long wrote: >> byte x = 0xF; >> ulong y = x >> 60; > > Surely you meant x << 60? As x >> 60 is going to be 0, even with a ulong. It doesn't work as intuitive as you'd expect: void main() { int x = 256;

Re: Bug in shifting

2018-12-13 Thread Neia Neutuladh via Digitalmars-d-learn
On Fri, 14 Dec 2018 00:16:51 +, Michelle Long wrote: > byte x = 0xF; > ulong y = x >> 60; "Error: shift by 60 is outside the range 0..31" This is the result of integer promotion rules. Change the 30 to a 60 and it works, and the result is, as you would expect, 0. > I thought D required

Re: Bug in shifting

2018-12-13 Thread Michelle Long via Digitalmars-d-learn
On Friday, 14 December 2018 at 02:17:20 UTC, Jonathan M Davis wrote: On Thursday, December 13, 2018 6:56:33 PM MST Steven Schveighoffer via Digitalmars-d-learn wrote: On 12/13/18 7:16 PM, Michelle Long wrote: > I've noticed the compiler is not throwing up errors and > warnings like it used to:

Re: Bug in shifting

2018-12-13 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, December 13, 2018 6:56:33 PM MST Steven Schveighoffer via Digitalmars-d-learn wrote: > On 12/13/18 7:16 PM, Michelle Long wrote: > > I've noticed the compiler is not throwing up errors and warnings like it > > used to: > > > > I thought D required breaks for cases? Seems it doesn't

Re: Bug in shifting

2018-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/13/18 7:16 PM, Michelle Long wrote: byte x = 0xF; ulong y = x >> 60; Surely you meant x << 60? As x >> 60 is going to be 0, even with a ulong. Does not compute the proper value. It seems that the shift amount is wrapped. My code is more complex. The code above does give an error. I

Re: Bug in shifting

2018-12-13 Thread Daniel Kozak via Digitalmars-d-learn
I do not understand you? What is wrong? It works ok. https://run.dlang.io/is/ZFf0FQ What do you mean by D required breaks for cases? On Fri, Dec 14, 2018 at 1:20 AM Michelle Long via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > byte x = 0xF; > ulong y = x >> 60; > > Does

Bug in shifting

2018-12-13 Thread Michelle Long via Digitalmars-d-learn
byte x = 0xF; ulong y = x >> 60; Does not compute the proper value. It seems that the shift amount is wrapped. My code is more complex. The code above does give an error. I am using the code in a template. If I change x to ulong it works as expected. I've noticed the compiler is not