Largest Factorial Represented Exactly In Floating Point System

• Sep 12th 2011, 10:20 AM
mathematicalbagpiper
Largest Factorial Represented Exactly In Floating Point System
"Find the largest integer \$\displaystyle n\$ such that \$\displaystyle n!\$ can be represented exactly in the floating point number system where the base is 2, the precision is 24, and the exponent ranges from -100 to 100.

Well, I don't even know where to start. I think it has something to do with expressing factorials as powers of 2, but other than that I haven't a bloody clue.
• Sep 12th 2011, 11:44 AM
CaptainBlack
Re: Largest Factorial Represented Exactly In Floating Point System
Quote:

Originally Posted by mathematicalbagpiper
"Find the largest integer \$\displaystyle n\$ such that \$\displaystyle n!\$ can be represented exactly in the floating point number system where the base is 2, the precision is 24, and the exponent ranges from -100 to 100.

Well, I don't even know where to start. I think it has something to do with expressing factorials as powers of 2, but other than that I haven't a bloody clue.

Well the number of binary digits is \$\displaystyle b=\lceil \lg(n!) \rceil\$

Of these \$\displaystyle z=\lfloor n/2 \rfloor + \lfloor n/4 \rfloor + ... + \lfloor n/2^{\lfloor\lg(n)\rfloor} \rfloor \$ are zeros.

So you now need \$\displaystyle b-z\le 24\$ and \$\displaystyle z \le 100\$

Now trial and error should find the answer pretty quickly (it is less than 20)

CB