Base: [skip ci] support of __round__ of QuantityPy
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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))) {
|
||||
|
||||
Reference in New Issue
Block a user