Created
October 15, 2014 07:12
-
-
Save Show-vars/5b79e89c75bb6c2c7fc2 to your computer and use it in GitHub Desktop.
Number e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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