Re: [go-nuts] Re: Conversion to Complex numbers

2020-03-27 Thread Ian Lance Taylor
On Fri, Mar 27, 2020 at 9:27 AM  wrote:
>
>
> On Friday, 27 March 2020 16:16:18 UTC, Stephen Illingworth wrote:
>>
>>
>>
>> On Friday, 27 March 2020 15:58:19 UTC, Brian Candler wrote:
>>>
>>> On Friday, 27 March 2020 15:42:08 UTC, stephen.i...@gmail.com wrote:

 // float -> complex

 const constFloat = 1

>>>
>>> Did you mean const constFloat = 1.0 ?
>>
>>
>> Yes. Results are the same.
>
>
> Corrected test program. Results are the same:
>
> package main
>
> import "testing"
>
> // int -> complex
>
> const constInt = 1
>
> func TestConstInt(t *testing.T) {
> _ = complex64(constInt)
> }
>
> const constIntExplicit = int(1)
>
> func TestConstIntExplicit(t *testing.T) {
> _ = complex64(constIntExplicit)
> }
>
> func TestVarInt(t *testing.T) {
> varInt := 1
> _ = complex64(varInt)
> }
>
> func TestVarIntExplicit(t *testing.T) {
> varIntExplicit := int(1)
> _ = complex64(varIntExplicit)
> }
>
> // float -> complex
>
> const constFloat = 1.0
>
> func TestConstFloat(t *testing.T) {
> _ = complex64(constFloat)
> }
>
> const constFloatExplicit = float64(1.0)
>
> func TestConstFloatExplicit(t *testing.T) {
> _ = complex64(constFloatExplicit)
> }
>
> func TestVarFloat(t *testing.T) {
> varFloat := 1.0
> _ = complex64(varFloat)
> }
>
> func TestVarFloatExplicit(t *testing.T) {
> varFloatExplicit := float64(1.0)
> _ = complex64(varFloatExplicit)
> }


The language spec does not support conversions between ints/floats and
complex numbers.  The exact rules are written down at
https://golang.org/ref/spec#Conversions.

But it's interesting that the behavior of typed constants changed
between 1.13 and 1.14.  I suspect that was changed in
https://golang.org/cl/187657.  The spec is not precisely clear on how
typed constant values should be handled.  Please open a bug report for
that case at https://golang.org/issue.  Thanks.

Ian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUo8jgfyJiYnO0PVg8wRZOOejo%3DU9S5c2oRQ0VeFj5Grg%40mail.gmail.com.


[go-nuts] Re: Conversion to Complex numbers

2020-03-27 Thread stephen . illingworth


On Friday, 27 March 2020 16:16:18 UTC, Stephen Illingworth wrote:
>
>
>
> On Friday, 27 March 2020 15:58:19 UTC, Brian Candler wrote:
>>
>> On Friday, 27 March 2020 15:42:08 UTC, stephen.i...@gmail.com wrote:
>>>
>>> // float -> complex
>>>
>>> const constFloat = 1
>>>
>>>
>> Did you mean const constFloat = 1.0 ?
>>
>
> Yes. Results are the same. 
>

Corrected test program. Results are the same:

package main

import "testing"

// int -> complex

const constInt = 1

func TestConstInt(t *testing.T) {
_ = complex64(constInt)
}

const constIntExplicit = int(1)

func TestConstIntExplicit(t *testing.T) {
_ = complex64(constIntExplicit)
}

func TestVarInt(t *testing.T) {
varInt := 1
_ = complex64(varInt)
}

func TestVarIntExplicit(t *testing.T) {
varIntExplicit := int(1)
_ = complex64(varIntExplicit)
}

// float -> complex

const constFloat = 1.0

func TestConstFloat(t *testing.T) {
_ = complex64(constFloat)
}

const constFloatExplicit = float64(1.0)

func TestConstFloatExplicit(t *testing.T) {
_ = complex64(constFloatExplicit)
}

func TestVarFloat(t *testing.T) {
varFloat := 1.0
_ = complex64(varFloat)
}

func TestVarFloatExplicit(t *testing.T) {
varFloatExplicit := float64(1.0)
_ = complex64(varFloatExplicit)
}
 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3332e4d4-edb9-4948-9a32-ae035fd110ad%40googlegroups.com.


[go-nuts] Re: Conversion to Complex numbers

2020-03-27 Thread stephen . illingworth


On Friday, 27 March 2020 15:58:19 UTC, Brian Candler wrote:
>
> On Friday, 27 March 2020 15:42:08 UTC, stephen.i...@gmail.com wrote:
>>
>> // float -> complex
>>
>> const constFloat = 1
>>
>>
> Did you mean const constFloat = 1.0 ?
>

Yes. Results are the same. 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5432c674-a237-493d-924c-9337b074156b%40googlegroups.com.


[go-nuts] Re: Conversion to Complex numbers

2020-03-27 Thread Brian Candler
On Friday, 27 March 2020 15:42:08 UTC, stephen.i...@gmail.com wrote:
>
> // float -> complex
>
> const constFloat = 1
>
>
Did you mean const constFloat = 1.0 ?

>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cadcfeb6-d19c-411d-b1c4-e0e86853b80f%40googlegroups.com.