Debian Codegraph @

js/src/tests/test262/language/statements/function/S13.2.1_A5_T2.js

raw
1 // Copyright 2009 the Sputnik authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 info: Closures are admitted
6 es5id: 13.2.1_A5_T2
7 description: >
8 Returning a function that approximates the derivative of f using
9 an interval of dx, which should be appropriately small
10 ---*/
11
12 // Return a function that approximates the derivative of f
13 // using an interval of dx, which should be appropriately small.
14 function derivative(f, dx) {
15 return function(x) {
16 return (f(x + dx) - f(x)) / dx;
17 };
18 }
19
20 //////////////////////////////////////////////////////////////////////////////
21 //CHECK#1
22 if (Math.abs(derivative(Math.sin, 0.0001)(0) - derivative(Math.sin, 0.0001)(2*Math.PI)) >= 1/65536.0) {
23 throw new Test262Error('#1: Math.abs(derivative(Math.sin, 0.0001)(0) - derivative(Math.sin, 0.0001)(2*Math.PI)) <= 1/65536.0');
24 }
25 //
26 //////////////////////////////////////////////////////////////////////////////
27
28 reportCompare(0, 0);