Member Avatar for misi

I have made a function in C to calculate large numbers for my future project,
because with the average calculators it's an impossible task.

Is that function working properly?
I would like to know that how far am I from the correct sum.

Factorial
65536! = 5.162948523097533 e +287193

Power
65536 ^ 65536 = 6.741140125499081 e +315652

Thank you!

Recommended Answers

All 3 Replies

Python says 5.16294852309750916500022794327 e287193 and 6.74114012549907340226906510470 e315652. For example

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from scipy.misc import factorial
>>> x = factorial(65536, exact=True)
>>> s = str(x)
>>> s[-1]
'0'
>>> s[:30]
'516294852309750916500022794327'
>>> len(s)
287194
>>> 
>>> x = 65536 ** 65536
>>> s = str(x)
>>> s[-1]
'6'
>>> s[:30]
'674114012549907340226906510470'
>>> len(s)
315653
Member Avatar for misi

Thank you!
I'm absolutely satisfied with the precision of my 64 bit double from Microsoft.
Multiplying then dividing thousands of times and still there is a relatively small loss... (RELATIVELY!)
Thanks again!

Another way to look at this ...

''' mpm_stuff.py 
comparing Python module mpmath result to C 64bit double results
'''

from mpmath import *

# convert to mpmath float
x = mpf(65536)

# set precision
mp.dps = 16

print("Factorial of 65536:")
print(fac(x))
print("5.162948523097533e+287193  (C)")
print("65536 to the Power of 65536:")
print(x**x)
print("6.741140125499081e+315652  (C)")


''' result ...
Factorial of 65536:
5.162948523097509e+287193
5.162948523097533e+287193  (C)
65536 to the Power of 65536:
6.741140125499073e+315652
6.741140125499081e+315652  (C)
'''

I would say you are close!

commented: yes! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.