From f11d9256a2c9a0d04bd5aa1041aef3911eae2a60 Mon Sep 17 00:00:00 2001 From: Noah Amsel Date: Thu, 3 Dec 2020 21:07:20 -0500 Subject: [PATCH] Properly convert infinity and NaN from C++ to Python --- include/pybind11_json/pybind11_json.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/pybind11_json/pybind11_json.hpp b/include/pybind11_json/pybind11_json.hpp index 774ea1b..5eebdc0 100644 --- a/include/pybind11_json/pybind11_json.hpp +++ b/include/pybind11_json/pybind11_json.hpp @@ -11,6 +11,7 @@ #include #include +#include #include "nlohmann/json.hpp" @@ -34,7 +35,7 @@ namespace pyjson else if (j.is_number()) { double number = j.get(); - if (number == std::floor(number)) + if (isfinite(number) && number == std::floor(number)) { return py::int_(j.get()); }