diff --git a/include/nanobind/nb_types.h b/include/nanobind/nb_types.h index 1a8c35e4..f384e621 100644 --- a/include/nanobind/nb_types.h +++ b/include/nanobind/nb_types.h @@ -371,10 +371,12 @@ class int_ : public object { : object(detail::int_from_obj(h.ptr()), detail::steal_t{}) { } template > = 0> - explicit int_(T value) - : object( - detail::type_caster::from_cpp(value, rv_policy::copy, nullptr), - detail::steal_t{}) { + explicit int_(T value) { + if constexpr (std::is_floating_point_v) + m_ptr = PyLong_FromDouble((double) value); + else + m_ptr = detail::type_caster::from_cpp(value, rv_policy::copy, nullptr).ptr(); + if (!m_ptr) raise_python_error(); }