Base: [skip ci] support of __round__ of QuantityPy

This commit is contained in:
wmayer
2020-02-16 21:50:06 +01:00
parent 177afc7b91
commit 1c8d0d1d84
2 changed files with 19 additions and 0 deletions

View File

@@ -48,6 +48,14 @@ Quantity(string) -- arbitrary mixture of numbers and chars defining a Quantity
</UserDocu>
</Documentation>
</Methode>
<Methode Name="__round__" Const="true">
<Documentation>
<UserDocu>
Return the Integral closest to x, rounding half toward even.
When an argument is passed, work like built-in round(x, ndigits).
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Value" ReadOnly="false">
<Documentation>
<UserDocu>Numeric Value of the Quantity (in internal system mm,kg,s)</UserDocu>

View File

@@ -205,6 +205,17 @@ PyObject* QuantityPy::getValueAs(PyObject *args)
return new QuantityPy(new Quantity(quant));
}
PyObject * QuantityPy::__round__ (PyObject *args)
{
double val= getQuantityPtr()->getValue();
Unit unit = getQuantityPtr()->getUnit();
Py::Float flt(val);
Py::Callable func(flt.getAttr("__round__"));
double rnd = static_cast<double>(Py::Float(func.apply(args)));
return new QuantityPy(new Quantity(rnd, unit));
}
PyObject * QuantityPy::number_float_handler (PyObject *self)
{
if (!PyObject_TypeCheck(self, &(QuantityPy::Type))) {