Angle between two vectors: 3D No magnitudes and/or sqrt()

Hey so I have a very efficient method to calculate the the components (x,y,z) of two vectors, and I want to calculate the angle between them. I am computing this for about 8 million individual entries.

My code is relatively fast, but the limiting point right now is the use of magnitudes, more specifically the sqrt function. I have explored some more efficient methods for computation of the sqrt but I wanted to see if there are more effecient methods unique to computation of the angle between two vectors. If I can be accurate to <1 degree that would be sufficient.

• You could compute $\cos^2\theta = \langle x,\rangle y^2/(\|x\| ^2\|y \|^2)$ to avoid the square roots, and use a table of approximate $\theta=\sqrt{\arccos x}$ values. Commented Oct 15, 2019 at 0:07
• this is truly due to my lack of knowledge on the applicable rule/identity. As I read this equation I still need to calculate the magnitude of x and y, or are you getting at that by squaring the magnitudes I can just avoid calculating the squareroot and calculate the sum of the squares? Commented Oct 15, 2019 at 0:13
• Squared magnitudes, yes. I botched the formula: $\cos^2\theta=\langle x,y\rangle^2/(\|x\|\|y\|)^2$ is what I meant. Commented Oct 15, 2019 at 0:26
• one last clarification (and thankyou already, I can already see a good option to implement this) what does <x,y> imply? Is that dot product or difference between the vectors? (this is all based on the assumption you are treating x and y as the two 3D vectors, not x and y components. Commented Oct 15, 2019 at 0:35
• Yes, dot product. Commented Oct 15, 2019 at 0:40