[C++-sig] V2: wrapping int/double bug(?)

Pearu Peterson pearu at cens.ioc.ee
Sat Apr 27 19:48:20 CEST 2002


Hi,

It seems that V2 does not distinguish between python int and
float types.

For example, if one defines (note the ordering of int and double methods)

  m.add(
    	 boost::python::class_<GiNaC::ex>("ex")

    	 .def_init(boost::python::args<int>())
    	 .def_init(boost::python::args<double const>())

	 .def("__add__",ex_add_double)
	 .def("__add__",ex_add_int)
  );

where

  const GiNaC::ex ex_add_int(const GiNaC::ex& lh,int const rh);
  const GiNaC::ex ex_add_double(const GiNaC::ex& lh,double const rh);

then in python:

>>> ex(2)
ex(numeric('2'))
>>> ex(2.3)
ex(numeric('2'))   <--- bug: float was converted to int
>>> ex(0)+2  
ex(numeric('2.0')) <--- bug: int was converted to float
>>> ex(0)+2.3
ex(numeric('2.2999999999999998224'))

That is, definitions
     .def_init(boost::python::args<double const>())
and
     .def("__add__",ex_add_int)
are ignored.

Any ideas how to fix this?

Regards,
	Pearu






More information about the Cplusplus-sig mailing list