Re: [go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-05-04 Thread Kamil Ziemian
Thank you for this Go Blog post and even more for encourage me to read the 
Go spec. C++ give spaces a bad name and teach me to avoid them.

sobota, 1 maja 2021 o 20:16:45 UTC+2 wagner riffel napisał(a):

> On Sat May 1, 2021 at 11:12 AM -03, Kamil Ziemian wrote:
> > Can you guide me to some materials about const in Go? Or maybe I should
> > finally read Go spec, which I avoid for a long time?
> >
>
> You shouldn't avoid to read the spec, it's not as complicated as others
> languages, and it's a great source of answers to such questions, i think
> this is a great material on Go constatns:
> https://blog.golang.org/constants
>
>

-- 
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/8391506a-6b5b-4ba5-9d5d-1d8bfda04c02n%40googlegroups.com.


Re: [go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-05-01 Thread peterGo
On Saturday, May 1, 2021 at 10:12:36 AM UTC-4 kziem...@gmail.com wrote:

> Can you guide me to some materials about const in Go? 
>
> Kamil
>
>>
>>
The Go Blog: Constants
https://blog.golang.org/constants

Peter

-- 
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/4f22816b-1dc0-41b9-9a2d-4aad10ee76ean%40googlegroups.com.


Re: [go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-05-01 Thread Kamil Ziemian
Thank you Brain Candler, this was probably thing that I missed: that
math.Sqrt2 is converted according to the context and I didn't think what
context fmt.Println gave it.

sob., 1 maj 2021 o 20:20 Brian Candler  napisał(a):

> Remember that while a constant may have unlimited precision, when you call
> fmt.Println() then it will get converted to a float64 value to be passed as
> an argument.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/q7StlcjMiII/unsubscribe.
> To unsubscribe from this group and all its topics, 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/30631b42-eb7b-43b6-891a-e9fa58a48038n%40googlegroups.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAB3gO8pme2_Nxu1b20GD1EqzHunSJM4qSJdu9wqd0gJ1oZBZ9g%40mail.gmail.com.


Re: [go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-05-01 Thread Brian Candler
Remember that while a constant may have unlimited precision, when you call 
fmt.Println() then it will get converted to a float64 value to be passed as 
an argument.

-- 
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/30631b42-eb7b-43b6-891a-e9fa58a48038n%40googlegroups.com.


Re: [go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-05-01 Thread 'wagner riffel' via golang-nuts
On Sat May 1, 2021 at 11:12 AM -03, Kamil Ziemian wrote:
> Can you guide me to some materials about const in Go? Or maybe I should
> finally read Go spec, which I avoid for a long time?
>

You shouldn't avoid to read the spec, it's not as complicated as others
languages, and it's a great source of answers to such questions, i think
this is a great material on Go constatns:
https://blog.golang.org/constants

-- 
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/CB244ROIRVC2.PS34B65JEIQ9%40pampas.


Re: [go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-05-01 Thread Kamil Ziemian
Thank you. I still need to learn more about floating point numbers, there 
is so many thing about them that can go wrong. At the same time, I believe 
this was in "A Tour of Go", I read that golang const are values with 
arbitrary precision. I hope that I don't mess this up. Since according to 
Go page math.Sqrt2 is very long const I was thinking that such things as 
printing is standard representation using fmt library is something that 
should work without problems.

Can you guide me to some materials about const in Go? Or maybe I should 
finally read Go spec, which I avoid for a long time?

Kamil

sobota, 1 maja 2021 o 02:36:13 UTC+2 Ian Lance Taylor napisał(a):

> On Fri, Apr 30, 2021 at 5:31 PM Kamil Ziemian  wrote:
> >
> > Wikipedia says that sqrt(2) = 1.414213562373095048..., so I would round 
> it to ...0950, while fmt.Println(math.Sqrt2) give me ...0951.
> > https://en.wikipedia.org/wiki/Square_root_of_2
> >
> > According to https://golang.org/pkg/math/#pkg-constants Sqrt2 is 
> defined with far more digits, so rounding precision shouldn't be an error.
> >
> > Can anyone tell me why math.Sqrt2 have such printing representation? 
> This little detail is just bogging me.
> >
> > I use go version go1.16.3 linux/amd64.
>
> Computer floating point numbers are not ideal floating point numbers.
>
> https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
>
> 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/02fc08a0-e8c5-4db5-9c08-dd1d1fb30fe9n%40googlegroups.com.


Re: [go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-04-30 Thread Ian Lance Taylor
On Fri, Apr 30, 2021 at 5:31 PM Kamil Ziemian  wrote:
>
> Wikipedia says that sqrt(2) = 1.414213562373095048..., so I would round it to 
> ...0950, while fmt.Println(math.Sqrt2) give me ...0951.
> https://en.wikipedia.org/wiki/Square_root_of_2
>
> According to https://golang.org/pkg/math/#pkg-constants Sqrt2 is defined with 
> far more digits, so rounding precision shouldn't be an error.
>
> Can anyone tell me why math.Sqrt2 have such printing representation? This 
> little detail is just bogging me.
>
> I use go version go1.16.3 linux/amd64.

Computer floating point numbers are not ideal floating point numbers.

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

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/CAOyqgcWOC_82sHF83wS%3DVRdYtgj8T%3DuQ1ffQgVgaf3MoBOuZCA%40mail.gmail.com.


[go-nuts] Why fmt.Println(math.Sqrt2) gives ...0951 not ...0950?

2021-04-30 Thread Kamil Ziemian

Hello.

Wikipedia says that sqrt(2) = 1.414213562373095048..., so I would round it 
to ...0950, while fmt.Println(math.Sqrt2) give me ...0951.
https://en.wikipedia.org/wiki/Square_root_of_2

According to https://golang.org/pkg/math/#pkg-constants Sqrt2 is defined 
with far more digits, so rounding precision shouldn't be an error.

Can anyone tell me why math.Sqrt2 have such printing representation? This 
little detail is just bogging me.

I use go version go1.16.3 linux/amd64.

Kamil

-- 
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/0dc400d7-95e0-40a8-a83a-4749fa1866ddn%40googlegroups.com.