Skip to content

Instantly share code, notes, and snippets.

@Show-vars
Created October 15, 2014 07:12
Show Gist options
  • Save Show-vars/5b79e89c75bb6c2c7fc2 to your computer and use it in GitHub Desktop.
Save Show-vars/5b79e89c75bb6c2c7fc2 to your computer and use it in GitHub Desktop.
Number e
package numbere;
public class NumberE {
public static void main(String[] args) {
double e = 2, el = 1, accuracy = Math.pow(10, -16);
long factorial = 1, i = 1;
long startTime = System.nanoTime();
while (el > accuracy) {
e += (el = 1.0 / (factorial *= ++i));
}
long endTime = System.nanoTime();
System.out.println("e = " + e + " in " + (endTime - startTime) + " ns ("+ (i - 1) +" iterations)");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment