 
             // object is a Double and is not NaN or infinity
             if let number = obj as? Double  {
-                let invalid = number.isInfinite || number.isNaN
-                return !invalid
+                return number.isFinite
             }
             // object is a Float and is not NaN or infinity
             if let number = obj as? Float  {
-                let invalid = number.isInfinite || number.isNaN
-                return !invalid
+                return number.isFinite
             }
 
             // object is Swift.Array

            }

            // object is NSNumber and is not NaN or infinity
            if let number = _SwiftValue.store(obj) as? NSNumber {
                let invalid = number.doubleValue.isInfinite || number.doubleValue.isNaN
                return !invalid

    
    mutating func serializeJSON(_ obj: Any) throws {

        // For better performance, the most expensive conditions to evaluate should be last.
        switch (obj) {
        case let str as String:
            try serializeString(str)
