Browse Source

Fixed IsNaN()

Dmitry Panov 6 years ago
parent
commit
eb0920a9fa
2 changed files with 4 additions and 3 deletions
  1. 2 1
      runtime.go
  2. 2 2
      runtime_test.go

+ 2 - 1
runtime.go

@@ -1478,7 +1478,8 @@ func IsNull(v Value) bool {
 
 
 // IsNaN returns true if the supplied value is NaN.
 // IsNaN returns true if the supplied value is NaN.
 func IsNaN(v Value) bool {
 func IsNaN(v Value) bool {
-	return v == _NaN
+	f, ok := v.assertFloat()
+	return ok && math.IsNaN(f)
 }
 }
 
 
 // IsInfinity returns true if the supplied is (+/-)Infinity
 // IsInfinity returns true if the supplied is (+/-)Infinity

+ 2 - 2
runtime_test.go

@@ -1201,13 +1201,13 @@ func TestInterruptInWrappedFunction(t *testing.T) {
 }
 }
 
 
 func TestNaN(t *testing.T) {
 func TestNaN(t *testing.T) {
-	if IsNaN(_NaN) {
+	if !IsNaN(_NaN) {
 		t.Fatal("IsNaN() doesn't detect NaN")
 		t.Fatal("IsNaN() doesn't detect NaN")
 	}
 	}
 	if IsNaN(Undefined()) {
 	if IsNaN(Undefined()) {
 		t.Fatal("IsNaN() says undefined is a NaN")
 		t.Fatal("IsNaN() says undefined is a NaN")
 	}
 	}
-	if IsNaN(NaN()) {
+	if !IsNaN(NaN()) {
 		t.Fatal("NaN() doesn't return NaN")
 		t.Fatal("NaN() doesn't return NaN")
 	}
 	}
 }
 }