Skip to content

Commit

Permalink
Fix handling of small magnitude quaternions
Browse files Browse the repository at this point in the history
The special case handling in glm::qua::pow is specifically intended for
the case when the magnitude is null. Even for magnitudes smaller than
epsilon, the common formula should be used. Because comparing a
floating-point value by equality triggers a warning through the
-Weveverything setting of clang, it must be selectively disabled for the
condition.
  • Loading branch information
qsantos committed Jul 28, 2020
1 parent dc2a00e commit d6d272e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion glm/ext/quaternion_exponential.inl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ namespace glm

//Prevent a division by 0 error later on
T VectorMagnitude = x.x * x.x + x.y * x.y + x.z * x.z;
if (glm::abs(VectorMagnitude - static_cast<T>(0)) < glm::epsilon<T>()) {
//Despite the compiler might say, we actually want to compare
//VectorMagnitude to 0. here; we could use denorm_int() compiling a
//project with unsafe maths optimizations might make the comparison
//always false, even when VectorMagnitude is 0.
if (VectorMagnitude < std::numeric_limits<T>::min()) {
//Equivalent to raising a real number to a power
return qua<T, Q>(pow(x.w, y), 0, 0, 0);
}
Expand Down

0 comments on commit d6d272e

Please sign in to comment.