summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorMichael Baudin <michael.baudin@scilab.org>2011-05-06 10:07:56 +0200
committerVincent COUVERT <vincent.couvert@scilab.org>2011-05-06 10:19:00 +0200
commit6346cbd2e5274deef40efa7c1472320e27db5ad1 (patch)
treed31f0d90a0d733f8888ccf944b4f6bdb5c181b15 /scilab/modules
parentb60a50edbacbeaf727153ebef85819c83e29f3dd (diff)
downloadscilab-6346cbd2e5274deef40efa7c1472320e27db5ad1.zip
scilab-6346cbd2e5274deef40efa7c1472320e27db5ad1.tar.gz
elementary_functions: updated comments in tests of sin, cos
Change-Id: Ief2e725e74959be9d752aba2b31f56f7021fc926
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/elementary_functions/tests/unit_tests/cos.tst4
-rw-r--r--scilab/modules/elementary_functions/tests/unit_tests/sin.tst22
2 files changed, 15 insertions, 11 deletions
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/cos.tst b/scilab/modules/elementary_functions/tests/unit_tests/cos.tst
index b14c688..be5e91e 100644
--- a/scilab/modules/elementary_functions/tests/unit_tests/cos.tst
+++ b/scilab/modules/elementary_functions/tests/unit_tests/cos.tst
@@ -31,9 +31,9 @@ if ( cos(-0) <> 1 ) then pause, end
31// The variable v contains correctly rounded values of the exact value of cos 31// The variable v contains correctly rounded values of the exact value of cos
32// on the exact double representing the various values of x. 32// on the exact double representing the various values of x.
33// For example, the floating point number which is closest to %pi/2 is 33// For example, the floating point number which is closest to %pi/2 is
34// 7074237752028440 * 2^(0-53+1), which can be written with the decimal string 34// 7074237752028440 * 2^-52, which can be written with the decimal string
35// 1.570796326794896558D+00. 35// 1.570796326794896558D+00.
36// We have cos(7074237752028440 * 2^(0-53+1)) = 6.123233995736765886...*10^-17 36// We have cos(7074237752028440 * 2^-52) = 6.123233995736765886...*10^-17
37// exactly. 37// exactly.
38// If Scilab had support for hex, we would have used it. 38// If Scilab had support for hex, we would have used it.
39// The exact values are computed in Wolfram Alpha. 39// The exact values are computed in Wolfram Alpha.
diff --git a/scilab/modules/elementary_functions/tests/unit_tests/sin.tst b/scilab/modules/elementary_functions/tests/unit_tests/sin.tst
index bbf3754..11b2172 100644
--- a/scilab/modules/elementary_functions/tests/unit_tests/sin.tst
+++ b/scilab/modules/elementary_functions/tests/unit_tests/sin.tst
@@ -1,7 +1,7 @@
1// ============================================================================= 1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr> 3// Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
4// Copyright (C) 2010 - DIGITEO - Michael Baudin 4// Copyright (C) 2010 - 2011 - DIGITEO - Michael Baudin
5// 5//
6// This file is distributed under the same license as the Scilab package. 6// This file is distributed under the same license as the Scilab package.
7// ============================================================================= 7// =============================================================================
@@ -28,27 +28,31 @@ if ( sin(0) <> 0 ) then pause, end
28if ( sin(-0) <> -0 ) then pause, end 28if ( sin(-0) <> -0 ) then pause, end
29 29
30 30
31// The following tests check cos for a small number of x in the range [0,pi]. 31// The following tests check sin for a small number of x in the range [0,pi].
32// The variable x contains correctly rounded values of the exact value of x. 32// The variable x contains correctly rounded values of the exact value of x.
33// The variable v contains correctly rounded values of the exact value of cos 33// The variable v contains correctly rounded values of the exact value of cos
34// on the exact double representing the various values of x. 34// on the exact double representing the various values of x.
35// For example, the floating point number which is closest to %pi/2 is 35// For example, the floating point number which is closest to %pi/2 is
36// 7074237752028440 * 2^(0-53+1), which can be written with the decimal string 36// 7074237752028440 * 2^-51, which can be written with the decimal string
37// 1.570796326794896558D+00. 37// 3.141592653589793116D+00.
38// We have cos(7074237752028440 * 2^(0-53+1)) = 6.123233995736765886...*10^-17 38// We have sin(7074237752028440 * 2^-51) = 1.224646799147353177...*10^-16
39// exactly. 39// exactly.
40//
40// If Scilab had support for hex, we would have used it. 41// If Scilab had support for hex, we would have used it.
41// The exact values are computed in Wolfram Alpha. 42// The exact values are computed in Wolfram Alpha.
42// We use more that 17 digits, which, if the decimal to binary conversion is 43// We use more that 17 digits, which, if the decimal to binary conversion is
43// correct, and if the rounding is round-to-nearest, must exactly produce 44// correct, and if the rounding is round-to-nearest, must exactly produce
44// values in this table. 45// values in this table.
46//
45// We avoid using values such as 2*%pi/3, which introduce one multiplication 47// We avoid using values such as 2*%pi/3, which introduce one multiplication
46// and one addition (the test fail is the multiplication or division 48// and one addition (the test fail is the multiplication or division
47// is not accurate, while the current test is not sensitive to this, i.e. 49// is not accurate, while the current test is not sensitive to this, i.e.
48// we test "cos", not "*"). 50// we test "sin", not "*").
51//
49// Failing this test may be caused by: 52// Failing this test may be caused by:
50// * a bad decimal to binary conversion, 53// * a bad decimal to binary conversion,
51// * a wrong implementation of cos. 54// * a wrong implementation of sin.
55//
52x = [ 56x = [
53 5.235987755982988157D-01 // %pi/6 57 5.235987755982988157D-01 // %pi/6
54 7.853981633974482790D-01 // %pi/4 58 7.853981633974482790D-01 // %pi/4
@@ -97,7 +101,7 @@ if ( or(rtol>ulptol) ) then pause, end
97// 101//
98// Check positive and negative normal numbers. 102// Check positive and negative normal numbers.
99x = [2^(-1022:-26) -2^(-1022:-26)]; 103x = [2^(-1022:-26) -2^(-1022:-26)];
100// Check that the values are close to 1. 104// Check that the values are close to x.
101// Our tolerance is : get the exact floating point number, 105// Our tolerance is : get the exact floating point number,
102// or its neighbour. 106// or its neighbour.
103S = sin(x); 107S = sin(x);
@@ -108,7 +112,7 @@ if ( or(rtol>ulptol) ) then pause, end
108// No matter how bad our library is, we must have abs(sin(x))<= 1. 112// No matter how bad our library is, we must have abs(sin(x))<= 1.
109// If this test fails, the math library is to be absolutely rejected. 113// If this test fails, the math library is to be absolutely rejected.
110if ( or(abs(S)>1) ) then pause, end 114if ( or(abs(S)>1) ) then pause, end
111// Compute the number of floats for which sin(x)<>1. 115// Compute the number of floats for which sin(x)<>x.
112// An excellent library should produce s=0. 116// An excellent library should produce s=0.
113// This failure happens for x=2^n and n usually close to -27. 117// This failure happens for x=2^n and n usually close to -27.
114notexact = sum(S<>x); 118notexact = sum(S<>x);