Re:Hired – Technical Interview Score
by nwellinghoff on Monday November 13, 2017 @05:43PM
(#15690980)
What do you mean you can "only meaningfully do 22 different factorials within the bounds of a 64-bit architecture anyway"?
Re:Hired – Technical Interview Score
by logfromblammo on Monday November 13, 2017 @08:21PM
(#15691813)
The 52-bit mantissa of a 64-bit double is only sufficient to represent all the significant figures of 22! and a 64-bit integer can only represent 20!, so if you want larger factorials with full precision, you need to use more bytes for your numeric representation.
Not many real-world applications require precision greater than a double, but pure mathematics can calculate millions of [decimal] digits of an irrational number just for amusement. A cryptography application, for instance, would need full precision, whereas an engineering problem might be perfectly fine with fewer significant digits.
Beyond that, "it depends" on what you're doing with the results. It's very likely that the developers' time would be better spent removing the factorial from the calculation that uses it, than on making the factorial calculation better at calculating factorials.
Besides that, since you can only meaningfully do 22 different factorials within the bounds of a 64-bit architecture anyway, just pre-calculate the results and make it a lookup table. Returns in O(c).