sin(x)
1 import std.math; 2 // f(x) = sin(x), f'(x) = cos(x) 3 auto x = dual(0.0, 1.0); 4 auto result = sin(x); 5 assert(approxEqual(result.re, 0.0)); // sin(0) = 0 6 assert(approxEqual(result.du, 1.0)); // cos(0) = 1 7 8 x = dual(PI / 2.0, 1.0); 9 result = sin(x); 10 assert(approxEqual(result.re, 1.0)); // sin(π/2) = 1 11 assert(approxEqual(result.du, 0.0)); // cos(π/2) = 0 12 13 // f(x) = sin(3x), f'(x) = 3cos(3x) 14 x = dual(5.0, 1.0); 15 result = sin(3 * x); 16 assert(approxEqual(result.re, std.math.sin(15.0))); 17 assert(approxEqual(result.du, 3.0 * std.math.cos(15.0)));
Sinus function on dual numbers.