Quaternion.ToAngleAxis returns NaN axis

I’m having trouble with ToAngleAxis for what should be a valid Quaternion:

Quaternion q1 = new Quaternion(0, 0, 0, 1);
Quaternion q2 = new Quaternion(0, 0, 0,-1);

q1.ToAngleAxis(out float angle1, out Vector3 axis1);
q2.ToAngleAxis(out float angle2, out Vector3 axis2);

Debug.Log(axis1);
Debug.Log(axis2);

// Output:
// (1.0, 0.0, 0.0)
// (NaN, NaN, NaN)

I’ve written a wrapper to work around this, but shouldn’t this give back a valid axis?
I’ve tried it in Unity 2018 and 2020

See this wikipedia article regarding how the axis and angle representations of a quaternion are derived. Both quaternions in your code specify a rotation around the axis (0, 0, 0), which theoretically speaking does not correspond to an actual non-zero rotation. The only reason the first quaternion returns a value for its axis and the second one doesn’t, is because the first quaternion is actually the value of Quaternion.identity. I suspect Unity does an internal check in ToAngleAxis() and spits out a default value if the Quaternion happens to be the identity.