On Fri, May 4, 2018 at 10:26 AM, Andrei Avram
<andrei.avram....@gmail.com> wrote:
>
> Today I ran into a situation that is strange to me. I ran the following code
> on two Linux machines (go run floor.go), on two Windows ones, and on Go
> Playground.
>
> package main
>
> import (
> "time"
> "math"
> )
>
> func main() {
> datetime := time.Now().Add(time.Hour * 24 * 7 * 4 * 12 * 3)
> seconds := -1 * int(time.Now().Sub(datetime).Seconds())
> a := 29030400
> b := float64(seconds) / float64(a)
>
> println("input:", b)
> println("floor:", math.Floor(b))
> }
>
> On Linux the output is:
>
> input: +3.000000e+000
> floor: +2.000000e+000
>
> On Windows and Playground:
>
> input: +3.000000e+000
> floor: +3.000000e+000
>
> As you can see, on Linux the floor value of float value 3 is rounded down to
> 2, while on Windows/Playground it's 3.
>
> The code was ran with Go 1.10 and 1.10.2.

The builtin println function already does rounding, so you are
comparing two rounded results.  Use fmt.Println instead to see the
real values you are working with.

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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to