From 060dd4380c2b77830d9d6288b8492500c75baf4c Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Sat, 22 Sep 2018 18:12:34 +0200 Subject: [PATCH] Added {Is,}NaN{,32} methods. --- math.go | 23 +++++++++++++++++++++++ math_test.go | 14 ++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 math.go create mode 100644 math_test.go diff --git a/math.go b/math.go new file mode 100644 index 0000000..0d9be4b --- /dev/null +++ b/math.go @@ -0,0 +1,23 @@ +package geom + +import "math" + +// IsNaN checks if the floating point number is not a number. +func IsNaN(f float64) bool { + return f != f +} + +// IsNaN32 checks if the floating point number is not a number. +func IsNaN32(f float32) bool { + return f != f +} + +// NaN returns not a floating point number. +func NaN() float64 { + return math.NaN() +} + +// NaN32 returns not a floating point number. +func NaN32() float32 { + return float32(NaN()) +} diff --git a/math_test.go b/math_test.go new file mode 100644 index 0000000..5a9ae78 --- /dev/null +++ b/math_test.go @@ -0,0 +1,14 @@ +package geom_test + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "opslag.de/schobers/geom" +) + +func TestIsNaN32(t *testing.T) { + assert.True(t, geom.IsNaN32(geom.NaN32())) + assert.False(t, geom.IsNaN32(0)) + assert.False(t, geom.IsNaN32(-1.43994e8)) +}