Helper API refactor (#40)
* api cleaup * updates * wtf * updates * snapshot. * tweaks * snapshot * api tweaks. * updates * updates * updates * changes. * updates * updates * sequence => seq * dont need to use curl, just using wget * fixing examples
This commit is contained in:
parent
43212f871f
commit
03708a90ef
100 changed files with 1687 additions and 1055 deletions
32
seq/util.go
Normal file
32
seq/util.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package seq
|
||||
|
||||
import "math"
|
||||
|
||||
func round(input float64, places int) (rounded float64) {
|
||||
if math.IsNaN(input) {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
sign := 1.0
|
||||
if input < 0 {
|
||||
sign = -1
|
||||
input *= -1
|
||||
}
|
||||
|
||||
precision := math.Pow(10, float64(places))
|
||||
digit := input * precision
|
||||
_, decimal := math.Modf(digit)
|
||||
|
||||
if decimal >= 0.5 {
|
||||
rounded = math.Ceil(digit)
|
||||
} else {
|
||||
rounded = math.Floor(digit)
|
||||
}
|
||||
|
||||
return rounded / precision * sign
|
||||
}
|
||||
|
||||
func f64i(value float64) int {
|
||||
r := round(value, 0)
|
||||
return int(r)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue