Calculating the value of e: Difference between revisions

Calculating the value of e in Dart
(Calculating the value of e in various BASIC dialents (Run BASIC and XBasic))
(Calculating the value of e in Dart)
Line 849:
{{out}}
<pre>e = 2.718281828459046</pre>
 
=={{header|Dart}}==
{{trans|C++}}
<syntaxhighlight lang="dart">void main() {
const double EPSILON = 1.0e-15;
double fact = 1;
double e = 2.0, e0;
int n = 2;
do {
e0 = e;
fact *= n++;
e += 1.0 / fact;
} while ((e-e0).abs() >= EPSILON);
print('The value of e = $e');
}</syntaxhighlight>
{{out}}
<pre>The value of e = 2.7182818284590455</pre>
 
=={{header|dc}}==
After 51 iterations the result is correct to 67 digits after the decimal, which gets as many digits as dc will display on a single line. After 1000 iterations the approximation is correct to 2,570 digits after the decimal. In each case you need to tell dc to (k)eep several digits past the target or else it will hit a plateau and stop improving before it reaches the desired precision.
2,122

edits