changeset 29164:b7a4460333c9

cosd.m: Use new improved sind.m for greater accuracy. * cosd.m: Advance phase by 90 degrees and then call sind() to take advantage of improved algorithm. Update BIST tests.
author Rik <rik@octave.org>
date Tue, 08 Dec 2020 20:09:19 -0800
parents 8f67ad8b3103
children 617d3aa713a4
files scripts/elfun/cosd.m
diffstat 1 files changed, 5 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/elfun/cosd.m	Tue Dec 08 13:25:03 2020 -0800
+++ b/scripts/elfun/cosd.m	Tue Dec 08 20:09:19 2020 -0800
@@ -37,16 +37,14 @@
     print_usage ();
   endif
 
-  I = x / 180;
-  y = cos (I .* pi);
-  I += 0.5;
-  y(I == fix (I) & isfinite (I)) = 0;
+  ## Advance phase by 90 degrees to turn sin in to cos and use sind. 
+  y = sind (x + 90);
 
 endfunction
 
 
-%!assert (cosd (0:10:80), cos (pi*[0:10:80]/180), -10*eps)
-%!assert (cosd ([0, 180, 360]) != 0)
-%!assert (cosd ([90, 270]) == 0)
+%!assert (cosd (10:20:360), cos ([10:20:360] * pi/180), 5*eps)
+%!assert (cosd ([-270, -90, 90, 270]) == 0)
+%!assert (cosd ([-360, -180, 0, 180, 360]), [1, -1, 1, -1, 1])
 
 %!error <Invalid call> cosd ()