Re: [go-nuts] Strange behaviour of left shift

2018-12-06 Thread Andy Balholm
That would definitely be possible. But it isn’t likely to happen. It would make the rule several times more complicated that it currently is, to fix something that only happens occasionally, is caught at compile time, and is easily taken care of with an explicit type conversion. That doesn’t

Re: [go-nuts] Strange behaviour of left shift

2018-12-05 Thread Michael Jones
Another way of saying it: "Go has Schrödinger's Constants." This captures the notion that a constant is of every type until you use it, whereupon it settles to the appropriate type based on the expectations of the use site. On Wed, Dec 5, 2018 at 2:55 PM Rob Pike wrote: > Most of this is

Re: [go-nuts] Strange behaviour of left shift

2018-12-05 Thread Rob Pike
Most of this is explained in blog.golang.org/constants. -rob On Thu, Dec 6, 2018 at 4:04 AM Andy Balholm wrote: > When an untyped integer constant is converted to a typed value, it always > becomes int. I suppose the rules could be made more complicated to handle > values that won’t fit in an

Re: [go-nuts] Strange behaviour of left shift

2018-12-05 Thread Andy Balholm
When an untyped integer constant is converted to a typed value, it always becomes int. I suppose the rules could be made more complicated to handle values that won’t fit in an int. But what if the value is too big to fit in a uint64? Should it be a float64 then? Andy > On Dec 5, 2018, at 8:54

Re: [go-nuts] Strange behaviour of left shift

2018-12-05 Thread James Bardin
On Wednesday, December 5, 2018 at 11:55:25 AM UTC-5, Michel Levieux wrote: > > Well the only thing I do in the main is : > > fmt.Println(v) >> > > Shouldn't the compiler statically type v to uint64? > I don't get the need to force type of v to uint64? > > Nope. You're passing an untyped constant

Re: [go-nuts] Strange behaviour of left shift

2018-12-05 Thread Burak Serdar
On Wed, Dec 5, 2018 at 9:55 AM Michel Levieux wrote: > > Well the only thing I do in the main is : > >> fmt.Println(v) > > > Shouldn't the compiler statically type v to uint64? > I don't get the need to force type of v to uint64? v is an untyped constant. When passed to Println, it is an int.

Re: [go-nuts] Strange behaviour of left shift

2018-12-05 Thread Michel Levieux
Well the only thing I do in the main is : fmt.Println(v) > Shouldn't the compiler statically type v to uint64? I don't get the need to force type of v to uint64? Le mer. 5 déc. 2018 à 17:45, Andy Balholm a écrit : > Apparently in your code the value is being assigned to an int. But it’s > too

Re: [go-nuts] Strange behaviour of left shift

2018-12-05 Thread Andy Balholm
Apparently in your code the value is being assigned to an int. But it’s too large for an int; it needs a uint64 to hold it. Andy > On Dec 5, 2018, at 8:35 AM, Michel Levieux wrote: > > Hi guys, > > With a colleague of mine, we've run into a strange issue today. When we look > at package

[go-nuts] Strange behaviour of left shift

2018-12-05 Thread Michel Levieux
Hi guys, With a colleague of mine, we've run into a strange issue today. When we look at package math, in const.go, we can see this line : MaxUint64 = 1<<64 - 1 > > which I assume works pretty well. But if I do the same in a test main and try to 'go run' it, with this line : const v = 1 << 64 -