In quaternion.h
inline vec4 quaternion::ToAxisAngle()
{
vec4 result;
const float angle = 2.0f * acos(w);
const float length = sqrt(1.0f - angle*angle);
result.xyz = vec3(x, y, z) / length;
result.w = angle;
return result;
}
At the time calculating length it should be length = sqrt(1.0f - w*w); . And we should also check for length != 0. As per your previous code we can get angle greater than 1 so at that time the length will be undefined.