Roots of a function: Difference between revisions

Content added Content deleted
(made local variable declarations explicit, added explicit types)
No edit summary
Line 699: Line 699:
.... MAY-BE at +1.99999999999999999950, f(x) = -8.674e-19</pre>
.... MAY-BE at +1.99999999999999999950, f(x) = -8.674e-19</pre>
NB: smallest increment for real type in D is real.epsilon = 1.0842e-19.
NB: smallest increment for real type in D is real.epsilon = 1.0842e-19.


=={{header|Dart}}==
{{trans|Scala}}
<lang delphi>import 'dart:async';

double fn(double x) => x * x * x - 3 * x * x + 2 * x;

double findRoots(Function(double) f, double start, double stop, double step, double epsilon) {
for (double x = start; x < stop; x = x + step) {
if (fn(x).abs() < epsilon) print(x);
}
}

main() {
findRoots(fn, -1.0, 3.0, 0.0001, 0.000000001);
}</lang>


=={{header|DWScript}}==
=={{header|DWScript}}==