Added {Is,}NaN{,32} methods.

This commit is contained in:
Sander Schobers 2018-09-22 18:12:34 +02:00
parent 8bcc0dff3f
commit 060dd4380c
2 changed files with 37 additions and 0 deletions

23
math.go Normal file
View File

@ -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())
}

14
math_test.go Normal file
View File

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