Time precision on Linux and Windows

Unit tests were needed on a new project I’m working on and a few weeks ago I wrote some. Last week, a colleague wrote some more, and when he ran all of them, mine were failing. Same code base, up to date, same tests. On my machine they were still passing. We jumped on the situation and saw math.Floor was giving a result on my machine, which runs on Ubuntu, and another one on his, on Windows.

The code is larger, but I’ve extracted and adapted what’s needed:

package main

import (

func main() {
	datetime := time.Now().Add(time.Hour * 24 * 7 * 4 * 12 * 3)
	seconds := -1 * int(time.Now().Sub(datetime).Seconds())
	a := 29030400
	x := float64(seconds)/float64(a)

	println("input:", x, "floor:", math.Floor(x))

Result on Ubuntu:

input: +3.000000e+000 floor: +2.000000e+000

Result on Windows:

input: +3.000000e+000 floor: +3.000000e+000

Continue reading Time precision on Linux and Windows