Re: [go-nuts] Re: why is the "1" in the code demoed in Go spec deduced as a "float64" value instead of an "int" value?

2018-03-07 Thread Volker Dobler

On Thursday, 8 March 2018 00:02:58 UTC+1, Ian Lance Taylor wrote:
>
>
> If we ignore the type context, then 
>
> var v int64 = 1 << s 
>
> fails on 32-bit systems if s > 31 (because 1 is assigned type int, 
> which is 32 bits, and the shifting a 32-bit value by more than 31 bits 
> gives you zero). 
>
> If we don't ignore the type context, then in 
>
> var v float32 = 1 << s 
>
> fails because we can't shift a float32. 
>
>
Thanks! This explanation is very clear. The spec already contains
an example of this rule: var k = uint64(1

Re: [go-nuts] Re: why is the "1" in the code demoed in Go spec deduced as a "float64" value instead of an "int" value?

2018-03-07 Thread digg


On Wednesday, March 7, 2018 at 6:02:58 PM UTC-5, Ian Lance Taylor wrote:
>
> On Wed, Mar 7, 2018 at 1:36 PM,  > 
> wrote: 
> > 
> > On Wednesday, March 7, 2018 at 4:26:19 PM UTC-5, di...@veryhaha.com 
> wrote: 
> >> 
> >> get it almost. 
> >> 
> >> But I feel 
> >> 
> >> var v = float32(1< >> is a little different to 
> >> var v float32 = 1< >> 
> >> 
> >> For the former one, we think "1" can be assumed as an "int". 
> >> But anyway, I get the main point of the design. 
> >> It is just a wording accuracy problem. 
> >> 
> > 
> > On the other hand, any bad if "1" is deduced as an "int" value? 
>
> If we ignore the type context, then 
>
> var v int64 = 1 << s 
>
> fails on 32-bit systems if s > 31 (because 1 is assigned type int, 
> which is 32 bits, and the shifting a 32-bit value by more than 31 bits 
> gives you zero). 
>
> If we don't ignore the type context, then in 
>
> var v float32 = 1 << s 
>
> fails because we can't shift a float32. 
>
> We could ignore the type context for float types but not for integer 
> types, but then the rule is even more complicated. 
>
> Ian 
>
>
>
Good design.
Thanks for the explanation.
 

>
>
> >> On Wednesday, March 7, 2018 at 3:59:48 PM UTC-5, Ian Lance Taylor 
> wrote: 
> >>> 
> >>> On Wed, Mar 7, 2018 at 12:54 PM, Volker Dobler 
> >>>  wrote: 
> >>> > Looks suspicious. Without crosschecking the Spec: Might be 
> >>> > a bug.  File an issue? 
> >>> 
> >>> It's not a bug.  See Andrey's reply. 
> >>> 
> >>> Ian 
> >>> 
> >>> 
> >>> 
> >>> > On Wednesday, 7 March 2018 21:39:32 UTC+1, di...@veryhaha.com 
> wrote: 
> >>> >> 
> >>> >> var s uint = 33 
> >>> >> var u2 = float64(1>>s)   // illegal: 1 has type float64, cannot 
> shift 
> >>> > 
> >>> > -- 
> >>> > You received this message because you are subscribed to the Google 
> >>> > Groups 
> >>> > "golang-nuts" group. 
> >>> > To unsubscribe from this group and stop receiving emails from it, 
> send 
> >>> > an 
> >>> > email to golang-nuts...@googlegroups.com. 
> >>> > For more options, visit https://groups.google.com/d/optout. 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "golang-nuts" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to golang-nuts...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: why is the "1" in the code demoed in Go spec deduced as a "float64" value instead of an "int" value?

2018-03-07 Thread Ian Lance Taylor
On Wed, Mar 7, 2018 at 1:36 PM,   wrote:
>
> On Wednesday, March 7, 2018 at 4:26:19 PM UTC-5, di...@veryhaha.com wrote:
>>
>> get it almost.
>>
>> But I feel
>>
>> var v = float32(1<> is a little different to
>> var v float32 = 1<>
>>
>> For the former one, we think "1" can be assumed as an "int".
>> But anyway, I get the main point of the design.
>> It is just a wording accuracy problem.
>>
>
> On the other hand, any bad if "1" is deduced as an "int" value?

If we ignore the type context, then

var v int64 = 1 << s

fails on 32-bit systems if s > 31 (because 1 is assigned type int,
which is 32 bits, and the shifting a 32-bit value by more than 31 bits
gives you zero).

If we don't ignore the type context, then in

var v float32 = 1 << s

fails because we can't shift a float32.

We could ignore the type context for float types but not for integer
types, but then the rule is even more complicated.

Ian




>> On Wednesday, March 7, 2018 at 3:59:48 PM UTC-5, Ian Lance Taylor wrote:
>>>
>>> On Wed, Mar 7, 2018 at 12:54 PM, Volker Dobler
>>>  wrote:
>>> > Looks suspicious. Without crosschecking the Spec: Might be
>>> > a bug.  File an issue?
>>>
>>> It's not a bug.  See Andrey's reply.
>>>
>>> Ian
>>>
>>>
>>>
>>> > On Wednesday, 7 March 2018 21:39:32 UTC+1, di...@veryhaha.com wrote:
>>> >>
>>> >> var s uint = 33
>>> >> var u2 = float64(1>>s)   // illegal: 1 has type float64, cannot shift
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> > Groups
>>> > "golang-nuts" group.
>>> > To unsubscribe from this group and stop receiving emails from it, send
>>> > an
>>> > email to golang-nuts...@googlegroups.com.
>>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: why is the "1" in the code demoed in Go spec deduced as a "float64" value instead of an "int" value?

2018-03-07 Thread Michael Jones
of course you can force it:
https://play.golang.org/p/QIWDeMDJlAq

On Wed, Mar 7, 2018 at 1:36 PM,  wrote:

>
>
> On Wednesday, March 7, 2018 at 4:26:19 PM UTC-5, di...@veryhaha.com wrote:
>>
>> get it almost.
>>
>> But I feel
>>
>> var v = float32(1<> is a little different to
>> var v float32 = 1<>
>>
>> For the former one, we think "1" can be assumed as an "int".
>> But anyway, I get the main point of the design.
>> It is just a wording accuracy problem.
>>
>>
> On the other hand, any bad if "1" is deduced as an "int" value?
>
>
>>
>>
>> On Wednesday, March 7, 2018 at 3:59:48 PM UTC-5, Ian Lance Taylor wrote:
>>>
>>> On Wed, Mar 7, 2018 at 12:54 PM, Volker Dobler
>>>  wrote:
>>> > Looks suspicious. Without crosschecking the Spec: Might be
>>> > a bug.  File an issue?
>>>
>>> It's not a bug.  See Andrey's reply.
>>>
>>> Ian
>>>
>>>
>>>
>>> > On Wednesday, 7 March 2018 21:39:32 UTC+1, di...@veryhaha.com wrote:
>>> >>
>>> >> var s uint = 33
>>> >> var u2 = float64(1>>s)   // illegal: 1 has type float64, cannot shift
>>> >
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "golang-nuts" group.
>>> > To unsubscribe from this group and stop receiving emails from it, send
>>> an
>>> > email to golang-nuts...@googlegroups.com.
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Michael T. Jones
michael.jo...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: why is the "1" in the code demoed in Go spec deduced as a "float64" value instead of an "int" value?

2018-03-07 Thread digg


On Wednesday, March 7, 2018 at 4:26:19 PM UTC-5, di...@veryhaha.com wrote:
>
> get it almost.
>
> But I feel
>
> var v = float32(1< is a little different to
> var v float32 = 1<
>
> For the former one, we think "1" can be assumed as an "int".
> But anyway, I get the main point of the design.
> It is just a wording accuracy problem.
>
>
On the other hand, any bad if "1" is deduced as an "int" value?
 

>
>
> On Wednesday, March 7, 2018 at 3:59:48 PM UTC-5, Ian Lance Taylor wrote:
>>
>> On Wed, Mar 7, 2018 at 12:54 PM, Volker Dobler 
>>  wrote: 
>> > Looks suspicious. Without crosschecking the Spec: Might be 
>> > a bug.  File an issue? 
>>
>> It's not a bug.  See Andrey's reply. 
>>
>> Ian 
>>
>>
>>
>> > On Wednesday, 7 March 2018 21:39:32 UTC+1, di...@veryhaha.com wrote: 
>> >> 
>> >> var s uint = 33 
>> >> var u2 = float64(1>>s)   // illegal: 1 has type float64, cannot shift 
>> > 
>> > -- 
>> > You received this message because you are subscribed to the Google 
>> Groups 
>> > "golang-nuts" group. 
>> > To unsubscribe from this group and stop receiving emails from it, send 
>> an 
>> > email to golang-nuts...@googlegroups.com. 
>> > For more options, visit https://groups.google.com/d/optout. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: why is the "1" in the code demoed in Go spec deduced as a "float64" value instead of an "int" value?

2018-03-07 Thread digg
get it almost.

But I feel

var v = float32(1<
> On Wed, Mar 7, 2018 at 12:54 PM, Volker Dobler 
> > wrote: 
> > Looks suspicious. Without crosschecking the Spec: Might be 
> > a bug.  File an issue? 
>
> It's not a bug.  See Andrey's reply. 
>
> Ian 
>
>
>
> > On Wednesday, 7 March 2018 21:39:32 UTC+1, di...@veryhaha.com wrote: 
> >> 
> >> var s uint = 33 
> >> var u2 = float64(1>>s)   // illegal: 1 has type float64, cannot shift 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "golang-nuts" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to golang-nuts...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: why is the "1" in the code demoed in Go spec deduced as a "float64" value instead of an "int" value?

2018-03-07 Thread Ian Lance Taylor
On Wed, Mar 7, 2018 at 12:54 PM, Volker Dobler
 wrote:
> Looks suspicious. Without crosschecking the Spec: Might be
> a bug.  File an issue?

It's not a bug.  See Andrey's reply.

Ian



> On Wednesday, 7 March 2018 21:39:32 UTC+1, di...@veryhaha.com wrote:
>>
>> var s uint = 33
>> var u2 = float64(1>>s)   // illegal: 1 has type float64, cannot shift
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.