It's in the spec under constants: arithmetic has arbitrary precision. When
you restrict to a floating point type by assigning to a variable you also
restrict the precision of the result.

On Thu, Nov 9, 2017, 4:35 PM <eriksro...@gmail.com> wrote:

> Why are the following unequal in Go? Is this a bug, or is it by design? If
> it's by design, why does this occur and is this type of behavior documented
> anywhere?
>
> https://play.golang.org/p/itEV9zwV2a
>
> package main
>
> import (
>     "fmt"
> )
>
> func main() {
>     x := 10.1
>
>     fmt.Println("x == 10.1:        ", x == 10.1)
>     fmt.Println("x*3.0 == 10.1*3.0:", x*3.0 == 10.1*3.0)
>     fmt.Println("x*3.0:            ", x*3.0)
>     fmt.Println("10.1*3.0:         ", 10.1*3.0)
> }
>
> Produces:
>
> x == 10.1:         true
> x*3.0 == 10.1*3.0: false
> x*3.0:             30.299999999999997
> 10.1*3.0:          30.3
>
>
> --
> 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.

Reply via email to