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)) +}