From f646975c3668bdb05376b3a14b62f59cd96c1b0e Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 31 Jul 2001 08:10:05 +0000 Subject: [PATCH] convert int/double to complex [SVN r10730] --- include/boost/python/conversions.hpp | 5 +++++ test/comprehensive.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/boost/python/conversions.hpp b/include/boost/python/conversions.hpp index 47f80989..cf753e2d 100644 --- a/include/boost/python/conversions.hpp +++ b/include/boost/python/conversions.hpp @@ -7,6 +7,7 @@ // producing this work. // // Revision History: +// 31 Jul 01 convert int/double to complex (Peter Bienstman) // 04 Mar 01 Fixed std::complex<> stuff to work with MSVC (David Abrahams) // 03 Mar 01 added: converters for [plain] char and std::complex // (Ralf W. Grosse-Kunstleve) @@ -93,6 +94,10 @@ namespace detail { template std::complex complex_from_python(PyObject* p, boost::python::type) { + if (PyInt_Check(p)) return std::complex(PyInt_AS_LONG(p)); + if (PyLong_Check(p)) return std::complex(PyLong_AsDouble(p)); + if (PyFloat_Check(p)) return std::complex(PyFloat_AS_DOUBLE(p)); + expect_complex(p); return std::complex( diff --git a/test/comprehensive.py b/test/comprehensive.py index db4f8b73..4ff34b48 100644 --- a/test/comprehensive.py +++ b/test/comprehensive.py @@ -1175,6 +1175,18 @@ test methodologies for wrapping functions that return a pointer '2.94' >>> '%.3g' % (dreal(c)) '6.35' + >>> '%.3g' % (dreal(3)) + '3' + >>> '%.3g' % (dreal(3L)) + '3' + >>> '%.3g' % (dreal(3.)) + '3' + >>> '%.3g' % (freal(3)) + '3' + >>> '%.3g' % (freal(3L)) + '3' + >>> '%.3g' % (freal(3.)) + '3' ''' #'