If you check (in R2020b):
>> X = dot(x,y) - sqrt(sum(x.^2)*sum(y.^2))
where as in R2016b, we get:
>> dot(x,y) - sqrt(sum(x.^2)*sum(y.^2))
Hence, in R2020b, we get:
0.000000000000000e+00 + 2.107342425544702e-08i
This is because the numerator dot(x,y) is "greater" than the denominator sqrt(sum(x.^2)*sum(y.^2)) albeit by a very small margin and hence the fraction X becomes greater than 1 and thus acos(X) gives complex value.
To avoid this my suggestion would be to establish a threshold precision to measure equality of two variables, for example you could have a check function so that if abs(x-y) < 1e-12 then x = y
function [a,b] = check(x,y)
if abs(x-y) < 1e-12
a = x;
b = a;
Now, you can do [a,b] = check(x,y) and then call acos(a/b). This will also help in any other function where numerical precision can cause problems.
Hope this helps!