2011-09-07 08:35:18 +02:00
// Copyright 2009 the Sputnik authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
2014-07-22 01:09:02 +02:00
/ * - - -
info : Cosine is a periodic function with period 2 * PI
2014-07-25 00:41:42 +02:00
es5id : 15.8 . 2.7 _A6
2014-07-22 01:09:02 +02:00
description : >
Checking if Math . cos ( x ) equals to Math . cos ( x + n * 2 * Math . PI ) with
precision 0.000000000003 , where n is an integer from 1 to 100 and
x is one of 10 float point values from - Math . PI to + Math . PI
-- - * /
2011-09-07 08:35:18 +02:00
// CHECK#1
2015-04-29 17:40:30 +02:00
var prec = 0.000000000003 ;
2011-09-07 08:35:18 +02:00
//prec = 0.000000000000001;
2015-04-29 17:40:30 +02:00
var period = 2 * Math . PI ;
var pernum = 100 ;
2011-09-07 08:35:18 +02:00
2015-04-29 17:40:30 +02:00
var a = - pernum * period ;
var b = pernum * period ;
var snum = 9 ;
var step = period / snum + 0.0 ;
var x = new Array ( ) ;
for ( var i = 0 ; i < snum ; i ++ )
2011-09-07 08:35:18 +02:00
{
x [ i ] = a + i * step ;
}
x [ 9 ] = a + period ;
var curval ;
var curx ;
var j ;
for ( i = 0 ; i < snum ; i ++ )
{
curval = Math . cos ( x [ i ] ) ;
curx = x [ i ] + period ;
j = 0 ;
while ( curx <= b )
{
curx += period ;
j ++ ;
if ( Math . abs ( Math . cos ( curx ) - curval ) >= prec )
{
2015-06-09 18:08:02 +02:00
$ERROR ( "#1: cos is found out to not be periodic:\n Math.abs(Math.cos(" + x [ i ] + ") - Math.cos(" + x [ i ] + " + 2*Math.PI*" + j + ")) >= " + prec + "\n Math.cos(" + x [ i ] + ") === " + curval + "\n Math.cos(" + curx + ") === " + Math . cos ( curx ) ) ;
2011-09-07 08:35:18 +02:00
}
}
}