From d11ce9e8ee6be9d2419d82f97c6477f1fb92b2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Mon, 25 Feb 2019 05:11:08 +0000 Subject: [PATCH] Fix logarithm of a real quaternion Former-commit-id: a82a1cd462014e7eeadc127061328b45f1e00ec2 --- qpms/wigner.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/qpms/wigner.h b/qpms/wigner.h index 074ed01..13e16fe 100644 --- a/qpms/wigner.h +++ b/qpms/wigner.h @@ -106,10 +106,17 @@ static inline qpms_quat_t qpms_quat_normalise(qpms_quat_t q) { /// Logarithm of a quaternion. static inline qpms_quat_t qpms_quat_log(const qpms_quat_t q) { const double n = qpms_quat_norm(q); - const double vc = acos(creal(q.a)/n) / qpms_quat_imnorm(q); - const qpms_quat_t r = {log(n) + cimag(q.a)*vc*I, - q.b*vc}; - return r; + const double imnorm = qpms_quat_imnorm(q); + if (imnorm != 0.) { + const double vc = acos(creal(q.a)/n) / qpms_quat_imnorm(q); + const qpms_quat_t r = {log(n) + cimag(q.a)*vc*I, + q.b*vc}; + return r; + } + else { + const qpms_quat_t r = {log(n), 0}; + return r; + } } /// Quaternion power to a real exponent.