For me it's a function that calculates factorial using iterators in Rust: fn factorial(i: u64) -> u64 { (1..=i).product() } In almost every other language this code would look messy or use some terrible recursion. For example in C it would look something like this: long factorial(int n) { int c; long result = 1; for (c = 1; c Or with recursion: long factorial(int n) { if (n == 0) return 1; else return(n * factorial(n…
Yet, since 20! is the last factorial representable in a u64, there is not much a point for these functions, and you should definitely check for nIn practice you would want the logarithm of the factorial, that is computed by the "lgamma" function from the C standard math.h. Is such a thing available in rust?
Edit: if you use doubles (which is more reasonable for that use case), you can also do that:
double factorial(double n) { return tgamma(1+n); }