I have a curve C with polar equation
$$r^2 = a^2\cos{2\theta} $$

And I am looking to find the length $x$ when $r=max$
Judging from the equation: $$r = \sqrt{a^2\cos{2\theta}} $$
R will be maximum at $\cos{2\theta}=1$
So the maximum value of $r$ is:
$$r = \sqrt{a^2} =a$$
However the derivative disagrees as: $$x^2=r^2\sin^2{\theta}=a^2\cos{2\theta}\,\sin^2{\theta} \\ \frac{d}{d\theta}\left (a^2\cos{2\theta}\,\sin^2{\theta} \right )=a^2(2\sin{\theta}\cos{\theta}-8\sin^3{\theta}\cos{\theta}) \\ \sin{\theta}=\frac{1}{2} \\ \theta= \frac{\pi}{6} \\ r= \frac{a}{\sqrt{2}}$$
What am I doing wrong?
Differentiating $r$ wrt to $\theta$ gives $\theta \mapsto |a|\frac{\sin 2 \theta}{\cos 2 \theta}$, which is zero when $\cos 2 \theta = \pm 1$. No disagreement there!
From this compute $x = r \cos \theta$. Since $\theta = 0$ maximizes $r$, the corresponding $x = |a|$.