Quaternion.FromToRotation - is it a bug? Possible workarounds?

Hello all. I just faced a very strange behavior when calculating rotations using Quaternion class. FromToRotation gives me different results with the same input depending on where it was called.
Code of the method below:

public virtual bool TryHorizontalAimTo(Vector3 Target)
    {
        Target.y = Ship.transform.position.y;
        
        Vector3 targetDirection = Vector3.Normalize(Target - Ship.transform.position);
        Quaternion rotation = Quaternion.FromToRotation(_actualForwardDirection.normalized, targetDirection);

        if (Ship.name == "PrototypeShip_2" && name == "TurretB")
        {
            Debug.Log("Target dir: " + targetDirection);
            Debug.Log("Forward dir: " + _actualForwardDirection);
            Debug.Log("Rotation: " + rotation.eulerAngles);
        }

        return TryApplyRotation(rotation);
    }

If called from Start() and from FixedUpdate() this method produces the following logs:
79849-start.png

If called from LateUpdate() it gives me the expected result of rotation around Y axis:
79850-lateupdate.png

As you can see in both cases I have (0.7, 0, 0.7) and (-0.7, 0, -0.7) vectors but rotations are different for some reason. I have Rigidbody attached to the GameObject but it is IsKinematic in both cases so this should not be a problem.

How should I handle with this? Are any workarounds exist?

Thanks in advance.

UPDATE: I tested it more and it seems no matter when the method is called. It looks like the issue appears only when object rotated at 45 degrees or 225 degrees which leads to (0.7, 0, 0.7) and (-0.7, 0, -0.7) vector parameters passed to FromToRotation. With other angles it wors fine.

A couple of things. Your “from” and “to” look to be very nearly colinear… exact opposite directions. There’s an infinite number of ways to rotate from one to the other. It’s the pathological undefined case for rotating with quaternions. The only case where you wouldn’t know for sure which way it’s going to go…

Now… as to the reason you’re getting different results. When you print a Vector3 to the console, you only get to see 1 decimal of precision. If you were to print the components with more precision you’d see that they’re probably slightly different (floats are notorious for rounding and precision errors accumulating as math is done to them). It’s those little differences that are going to tip the Quaternion math to choosing one rotation over another.