Created
May 18, 2020 14:40
-
-
Save AlexisTM/ad72976d89da8360cd9ddd4d120701b7 to your computer and use it in GitHub Desktop.
Very fast algorithm for the a first approximation of a very large factorial (10 decimals)
This file contains 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
function factorial(number) { | |
let result = 0; | |
for(let i = number; i > 0; --i) { | |
result += Math.log10(i); | |
} | |
return result; | |
} | |
function scientific_factorial(number) { | |
let fact = factorial(number); | |
let value = Math.pow(10, fact%1); | |
let exponent = Math.round(fact); | |
return [value, exponent]; | |
} | |
let result = scientific_factorial(100000); | |
console.log("value:", result[0], "exponent:", result[1]); | |
console.log(result[0].toString() + "e" + result[1].toString()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment