1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15var delta = 0.0001; 16var mod_m = 1.0 - delta; 17var mod_p = 1.0 + delta; 18 19assert (isNaN (Math.cos (NaN))); 20assert ((Math.cos (+0.0)) == 1.0); 21assert ((Math.cos (-0.0)) == 1.0); 22assert (isNaN (Math.cos (Infinity))); 23assert (isNaN (Math.cos (-Infinity))); 24 25assert (Math.cos (Math.PI) > -1.0 * mod_p); 26assert (Math.cos (Math.PI) < -1.0 * mod_m); 27 28assert (Math.cos (Math.PI / 2) > -delta); 29assert (Math.cos (Math.PI / 2) < +delta); 30assert (Math.cos (-Math.PI / 2) > -delta); 31assert (Math.cos (-Math.PI / 2) < +delta); 32 33assert (Math.cos (Math.PI / 4) > mod_m * Math.SQRT2 / 2); 34assert (Math.cos (Math.PI / 4) < mod_p * Math.SQRT2 / 2); 35 36assert (Math.cos (-Math.PI / 4) > mod_m * Math.SQRT2 / 2); 37assert (Math.cos (-Math.PI / 4) < mod_p * Math.SQRT2 / 2); 38 39assert (isNaN (Math.sin (NaN))); 40assert (1.0 / Math.sin (0.0) == Infinity); 41assert (1.0 / Math.sin (-0.0) == -Infinity); 42assert (isNaN (Math.sin (Infinity))); 43assert (isNaN (Math.sin (-Infinity))); 44 45assert (Math.sin (Math.PI) > -delta); 46assert (Math.sin (Math.PI) < +delta); 47 48assert (Math.sin (Math.PI / 2) > 1.0 * mod_m); 49assert (Math.sin (Math.PI / 2) < 1.0 * mod_p); 50 51assert (Math.sin (-Math.PI / 2) > -1.0 * mod_p); 52assert (Math.sin (-Math.PI / 2) < -1.0 * mod_m); 53 54assert (Math.sin (Math.PI / 4) > mod_m * Math.SQRT2 / 2); 55assert (Math.sin (Math.PI / 4) < mod_p * Math.SQRT2 / 2); 56 57assert (Math.sin (-Math.PI / 4) > -mod_p * Math.SQRT2 / 2); 58assert (Math.sin (-Math.PI / 4) < -mod_m * Math.SQRT2 / 2); 59 60var step = 0.01; 61 62for (var x = -2 * Math.PI; x <= 2 * Math.PI; x += step) 63{ 64 var s = Math.sin (x); 65 var c = Math.cos (x); 66 var sqr_s = s * s; 67 var sqr_c = c * c; 68 69 assert (sqr_s + sqr_c > mod_m); 70 assert (sqr_s + sqr_c < mod_p); 71} 72