75 :
public boost::python::def_visitor<BoostNumberPythonVisitor<BoostNumber>>
79 template<
class PyClass>
80 void visit(PyClass & cl)
const 82 cl.def(bp::init<>(
"Default constructor.", bp::arg(
"self")))
83 .def(bp::init<BoostNumber>(
"Copy constructor.", bp::args(
"self",
"value")))
91 .def(bp::init<std::string>(
"Constructor from a string.", bp::args(
"self",
"str_value")));
93 PINOCCHIO_COMPILER_DIAGNOSTIC_PUSH
94 PINOCCHIO_COMPILER_DIAGNOSTIC_IGNORED_SELF_ASSIGN_OVERLOADED
95 cl.def(bp::self + bp::self)
96 .def(bp::self += bp::self)
97 .def(bp::self - bp::self)
98 .def(bp::self -= bp::self)
99 .def(bp::self * bp::self)
100 .def(bp::self *= bp::self)
101 .def(bp::self / bp::self)
102 .def(bp::self /= bp::self)
104 .def(bp::self < bp::self)
105 .def(bp::self <= bp::self)
106 .def(bp::self > bp::self)
107 .def(bp::self >= bp::self)
108 .def(bp::self == bp::self)
109 .def(bp::self != bp::self)
110 .def(bp::self_ns::pow(bp::self_ns::self,
long()));
111 PINOCCHIO_COMPILER_DIAGNOSTIC_POP
113 cl.def(
"str", &BoostNumber::str, bp::args(
"self",
"precision",
"scientific"))
116 "default_precision",
static_cast<unsigned (*)()
>(BoostNumber::default_precision),
117 "Get the default precision of the class.")
119 "default_precision",
static_cast<void (*)(
unsigned)
>(BoostNumber::default_precision),
120 bp::arg(
"digits10"),
"Set the default precision of the class.")
121 .staticmethod(
"default_precision")
124 "precision",
static_cast<unsigned (BoostNumber::*)() const
>(&BoostNumber::precision),
125 bp::arg(
"self"),
"Get the precision of this.")
127 "precision",
static_cast<void (BoostNumber::*)(
unsigned)
>(&BoostNumber::precision),
128 bp::args(
"self",
"digits10"),
"Set the precision of this.")
130 .def(
"__float__", &cast<double>, bp::arg(
"self"),
"Cast to float.")
131 .def(
"__int__", &cast<int64_t>, bp::arg(
"self"),
"Cast to int.")
133 .def(
"__str__", &print, bp::arg(
"self"))
134 .def(
"__repr__", &print, bp::arg(
"self"))
137 "set_display_precision", &set_display_precision, bp::arg(
"digit"),
138 "Set the precision when printing values.")
139 .staticmethod(
"set_display_precision")
142 "get_display_precision", &get_display_precision,
143 "Get the precision when printing values.",
144 bp::return_value_policy<bp::copy_non_const_reference>())
145 .staticmethod(
"get_display_precision")
153 static void expose(
const std::string & type_name)
155 bp::class_<BoostNumber>(type_name.c_str(),
"", bp::no_init)
158 eigenpy::registerNewType<BoostNumber>();
159 eigenpy::registerCommonUfunc<BoostNumber>();
161#define IMPLICITLY_CONVERTIBLE(T1, T2) bp::implicitly_convertible<T1, T2>(); 164 IMPLICITLY_CONVERTIBLE(
double, BoostNumber);
165 IMPLICITLY_CONVERTIBLE(
float, BoostNumber);
166 IMPLICITLY_CONVERTIBLE(
long int, BoostNumber);
167 IMPLICITLY_CONVERTIBLE(
int, BoostNumber);
168 IMPLICITLY_CONVERTIBLE(
long, BoostNumber);
169 IMPLICITLY_CONVERTIBLE(
unsigned int, BoostNumber);
170 IMPLICITLY_CONVERTIBLE(
unsigned long int, BoostNumber);
171 IMPLICITLY_CONVERTIBLE(
bool, BoostNumber);
173#undef IMPLICITLY_CONVERTIBLE 175 eigenpy::registerCast<BoostNumber, double>(
false);
176 eigenpy::registerCast<double, BoostNumber>(
true);
177 eigenpy::registerCast<BoostNumber, float>(
false);
178 eigenpy::registerCast<float, BoostNumber>(
true);
179 eigenpy::registerCast<BoostNumber, long>(
false);
180 eigenpy::registerCast<long, BoostNumber>(
true);
181 eigenpy::registerCast<BoostNumber, int>(
false);
182 eigenpy::registerCast<int, BoostNumber>(
true);
184 eigenpy::registerCast<BoostNumber, int64_t>(
false);
185 eigenpy::registerCast<int64_t, BoostNumber>(
true);
190 static T cast(
const BoostNumber & self)
192 return static_cast<T
>(self);
195 static std::string print(
const BoostNumber & self)
197 return self.str(get_display_precision(), std::ios_base::dec);
200 static void set_display_precision(
const int digit)
202 get_display_precision() = digit;
205 static int & get_display_precision()
207 static int precision = BoostNumber::default_precision();