Skip to content

Instantly share code, notes, and snippets.

@gonzaloserrano
Created April 10, 2017 16:34
Show Gist options
  • Save gonzaloserrano/70ec86742536e42512c5a79d50d8bf20 to your computer and use it in GitHub Desktop.
Save gonzaloserrano/70ec86742536e42512c5a79d50d8bf20 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
"os"
)
func main() {
var vf = []float64{
4.9790119248836735e+00,
7.7388724745781045e+00,
-2.7688005719200159e-01,
-5.0106036182710749e+00,
9.6362937071984173e+00,
2.9263772392439646e+00,
5.2290834314593066e+00,
2.7279399104360102e+00,
1.8253080916808550e+00,
-8.6859247685756013e+00,
}
var ceil = []float64{
5.0000000000000000e+00,
8.0000000000000000e+00,
0.0000000000000000e+00,
-5.0000000000000000e+00,
1.0000000000000000e+01,
3.0000000000000000e+00,
6.0000000000000000e+00,
3.0000000000000000e+00,
2.0000000000000000e+00,
-8.0000000000000000e+00,
}
for i := 0; i < len(vf); i++ {
println(math.Ceil(vf[i]), int(math.Ceil(vf[i])), int(vf[i]))
if f := math.Ceil(vf[i]); ceil[i] != f {
fmt.Sprintf("Ceil(%g) = %g, want %g", vf[i], f, ceil[i])
os.Exit(1)
}
}
}
Copy link

ghost commented Apr 10, 2017

result:

+5.000000e+000
5
4

+8.000000e+000
8
7

-0.000000e+000
0
0

-5.000000e+000
-5
-5

+1.000000e+001
10
9

+3.000000e+000
3
2

+6.000000e+000
6
5

+3.000000e+000
3
2

+2.000000e+000
2
1

-8.000000e+000
-8
-8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment