Today I used atand(x) and atan(x). To my great surprise atand(x) was not just a little bit slower than atan(x) but is incredibly slow compared to atan(x)?
I tried to verify this by using the code below. First a time measurement for atan(x), than for atan(x) multiplied with 360/2/pi to go to degrees and finally one loop for atand(x). The results I found were:
Elapsed time is 0.047019 seconds. -> atan(x)
Elapsed time is 0.062016 seconds. -> atan(x)*360/2/pi
Elapsed time is 4.166911 seconds. -> atand(x)
And finally a test to check if atand(x) yielded identical results to atan(x) which was 'true' for all arguments tested.
This would mean that one should never use atan2d because atan2(x)*360/2/pi is much and much quicker? Why is there even a atan2d(x) function or why is it so slow?
Kind regards,
Ernst Jan Grift
clear alln=1000000;x_rad=zeros(1,n);x_rad_to_d=zeros(1,n);x_d=zeros(1,n);arg=rand(1,n);ticfor i=1:n x_rad(i)=atan(arg(n));endtocticfor i=1:n x_rad_to_d(i)=atan(arg(n))*360/2/pi;endtocticfor i=1:n x_d(i)=atand(arg(n));endtocsame=x_rad_to_d==x_d;all(same)
Best Answer