summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-07-08 23:40:33 +0200
committerDimitri Sokolyuk <demon@dim13.org>2017-07-08 23:40:33 +0200
commitfecbe7a5aa14bb18bc3bc5cbe865722ffd18895c (patch)
tree9e3cae73fa76ad76ed59b9a2f20f36e9316cb607
parentef5f658c66e3cff4b85202e17d22c39d54af1c9b (diff)
Drop RoundN
-rw-r--r--equals.go4
-rw-r--r--round.go10
-rw-r--r--round_test.go26
3 files changed, 2 insertions, 38 deletions
diff --git a/equals.go b/equals.go
index 824077c..007aa4a 100644
--- a/equals.go
+++ b/equals.go
@@ -1,8 +1,8 @@
package float
-const epsilon = 1e-6
+var Epsilon = 1e-6
// Equals compares two float values
func Equals(a, b float64) bool {
- return (a-b) < epsilon && (b-a) < epsilon
+ return (a-b) < Epsilon && (b-a) < Epsilon
}
diff --git a/round.go b/round.go
index 1962ea6..d754f1a 100644
--- a/round.go
+++ b/round.go
@@ -2,16 +2,6 @@ package float
import "math"
-// ISO 80000-1:2012
-// q = \sgn(y) \left\lfloor \left| y \right| + 0.5 \right\rfloor
-// = -\sgn(y) \left\lceil -\left| y \right| - 0.5 \right\rceil
-
-// RoundN a float value to n decimal places
-func RoundN(x float64, n int) float64 {
- pow := math.Pow(10, float64(n))
- return Round(x*pow) / pow
-}
-
// Round a float value
// https://www.cockroachlabs.com/blog/rounding-implementations-in-go/
func Round(x float64) float64 {
diff --git a/round_test.go b/round_test.go
index 6033156..7cacc98 100644
--- a/round_test.go
+++ b/round_test.go
@@ -6,32 +6,6 @@ import (
"testing"
)
-func TestRound2(t *testing.T) {
- testCases := []struct {
- in, out float64
- }{
- {0.0, 0.0},
- {0.3, 0.3},
- {0.333, 0.33},
- {0.334, 0.33},
- {0.335, 0.34},
- {-0.333, -0.33},
- {-0.334, -0.33},
- {-0.335, -0.34},
- {495.17999999999995, 495.18},
- {-495.17999999999995, -495.18},
- {0.115, 0.12},
- {-0.115, -0.12},
- }
- for _, tc := range testCases {
- t.Run(fmt.Sprint(tc.in), func(t *testing.T) {
- if r := RoundN(tc.in, 2); r != tc.out {
- t.Errorf("got %v, want %v", r, tc.out)
- }
- })
- }
-}
-
func TestRound(t *testing.T) {
negZero := math.Copysign(0, -1)
testCases := []struct {