Skip to content

Commit

Permalink
improve RotationPy::number_power_handler: make computation more effic…
Browse files Browse the repository at this point in the history
…ient and less prone to round-off errors
  • Loading branch information
wwmayer committed Oct 7, 2019
1 parent 67562ac commit ccbd579
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/Base/RotationPyImp.cpp
Expand Up @@ -441,19 +441,16 @@ PyObject * RotationPy::number_power_handler (PyObject* self, PyObject* other, Py
}

Rotation a = static_cast<RotationPy*>(self)->value();

long b = Py::Int(other);
if(!b)
return new RotationPy(Rotation());

if(b < 0) {
b = -b;
a.invert();
}
auto res = a;
for(--b;b;--b)
res *= a;
return new RotationPy(res);
Vector3d axis;
double rfAngle;

a.getRawValue(axis, rfAngle);
rfAngle *= b;
a.setValue(axis, rfAngle);

return new RotationPy(a);
}

PyObject* RotationPy::number_add_handler(PyObject * /*self*/, PyObject * /*other*/)
Expand Down

0 comments on commit ccbd579

Please sign in to comment.