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 <kziem...@gmail.com> 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.

Reply via email to