File: sin.dia.ref

package info (click to toggle)
scilab 5.2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 334,832 kB
  • ctags: 52,586
  • sloc: xml: 526,945; ansic: 223,590; fortran: 163,080; java: 56,934; cpp: 33,840; tcl: 27,936; sh: 20,397; makefile: 9,908; ml: 9,451; perl: 1,323; cs: 614; lisp: 30
file content (59 lines) | stat: -rw-r--r-- 2,876 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
//
//  This file is distributed under the same license as the Scilab package.
// =============================================================================
// <-- JVM NOT MANDATORY -->
// unit tests for sin() function (element wise cosine)
// =============================================================================
// 1. Interface
// ============
if execstr("sin()"   ,"errcatch")           == 0 then bugmes();quit;end
if execstr("sin(1,2)","errcatch")           == 0 then bugmes();quit;end
if execstr("sin(''my string'')","errcatch") == 0 then bugmes();quit;end
// 2. Singular Values
// ==================
rt2 = sqrt (2);
rt3 = sqrt (3);
x = [0, %pi/6 , %pi/4 , %pi/3 , %pi/2 , 2*%pi/3 , 3*%pi/4 , 5*%pi/6 , %pi];
v = [0, 1/2   , rt2/2 , rt3/2 , 1     , rt3/2   , rt2/2   , 1/2     , 0  ];
if or(abs(sin(x)-v) > sqrt(%eps)) then bugmes();quit;end
// 3. Not A Number
// ===============
if ~isnan(sin(%nan)) then bugmes();quit;end
if ~isnan(sin(-%nan)) then bugmes();quit;end
// 4. Limit values
// ===============
if ~isnan(real(sin(%inf)))    then bugmes();quit;end
if imag(sin(%inf)) <> 0       then bugmes();quit;end
if ~isnan(real(sin(-%inf)))   then bugmes();quit;end
if imag(sin(-%inf)) <> 0      then bugmes();quit;end
// 5. Properties
// =============
A = rand(100,100);
B = rand(100,100);
// sin(-x) = - sin(x)
if or( sin(-A) + sin(A) > %eps) then bugmes();quit;end
// sin(%pi/2 - x) = cos(x)
if or( sin(%pi/2 - A) - cos(A) > %eps) then bugmes();quit;end
// sin(%pi - x) = sin(x)
if or( sin(%pi - A) - sin(A) > %eps) then bugmes();quit;end
// sin(%pi + x) = - sin(x)
if or( sin(%pi + A) + sin(A) > %eps) then bugmes();quit;end
// sin(%pi/2 + x) = cos(x)
if or( sin(%pi/2 + A) - cos(A) > %eps) then bugmes();quit;end
// cos^2(a) + sin^2(a) = 1
if or( (cos(A)).^2 + (sin(A)).^2 - 1 > %eps) then bugmes();quit;end
// cos(a + b) = cos(a) cos(b) - sin(a) sin(b)
if or( cos(A + B) - cos(A).*cos(B) + sin(A).*sin(B) > 2 * %eps) then bugmes();quit;end
// cos(a -b) = cos(a) cos(b) + sin(a) sin(b)
if or( cos(A - B) - cos(A).*cos(B) - sin(A).*sin(B) > 2 * %eps) then bugmes();quit;end
// sin(a + b) = sin(a) cos(b) + sin(b) cos(a)
if or( sin(A + B) - sin(A).*cos(B) - sin(B).*cos(A) > 2 * %eps) then bugmes();quit;end
// sin(a -b) = sin(a) cos(b) - sin(b) cos(a)
if or( sin(A - B) - sin(A).*cos(B) + sin(B).*cos(A) > 2 * %eps) then bugmes();quit;end
// cos(2a) = cos^2(a) - sin^2(a) = 2 cos^2(a) - 1 = 1 - 2 sin^2(a)
if or( cos(2*A) - (cos(A)).^2 + (sin(A)).^2 > 2 * %eps ) then bugmes();quit;end
if or( cos(2*A) - 2 * (cos(A)).^2 + 1 > 2 * %eps ) then bugmes();quit;end
if or( cos(2*A) - 1 + 2 * (sin(A)).^2 > 2 * %eps ) then bugmes();quit;end