4 ms·
> The downside of this trick is that now, for example, ramanujan2(5) and ramanujan2(5.0) give different results. In some contexts, the improved accuracy may not
by kccqzy 4y ago
> The downside of this trick is that now, for example, ramanujan2(5) and ramanujan2(5.0) give different results. In some contexts, the improved accuracy may not be worth the inconsistency.
Why not just use
fact = math.floor(fact)
instead of int()?
I hate functions that randomly decides to return a different type too.
- lifthrasiir 4y agoTo be fair functions like `abs(x)` are expected to return int when x is int and float when x is float. Factorial acts same with respect to types so it is not that unreasonable. The real problem is that `fact` is not the actual factorial but its approximation (doubly so because it goes through float anyway). So all extra precision provided by bigint is useless.
- hgsgm 4y ago