473,465 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

-1.#IND000 problem

2 New Member
I am working on code to calculate the factorial using below function:

int factorial (int num)
{
if (num==1)
return 1;
return factorial(num-1)*num; // recursive call
}


And I need to calculate the numbers from 1 to 255…

The problem occurs when it reaches number 35 and above, it starts to give -1.#IND000 as result for the calculation…

I tried to define the variable as float, double , long double but it doesn’t work!
May 25 '08 #1
6 5374
Laharl
849 Recognized Expert Contributor
Those numbers are far too large for even long doubles. You'll need to find (or write) a library capable of working with such huge numbers.
May 25 '08 #2
Motoma
3,237 Recognized Expert Specialist
Hi iCe CreaM,

You will want to take a look at an Arbitrary-precision arithmetic library, or else create your own to help with this task.
If you take a look at the article I hyperlinked, there is a section mentioning factorials!

Good luck,
Motoma


I am working on code to calculate the factorial using below function:

int factorial (int num)
{
if (num==1)
return 1;
return factorial(num-1)*num; // recursive call
}


And I need to calculate the numbers from 1 to 255…

The problem occurs when it reaches number 35 and above, it starts to give -1.#IND000 as result for the calculation…

I tried to define the variable as float, double , long double but it doesn’t work!
May 26 '08 #3
iCe CreaM
2 New Member
first of all thanks guys for your replies...

i gounf the library http://gmplib.org/#WHAT

they said that it is the best in this regard but i couldn't know how to install it or use it in my C++ program :(

i tried to read the manual but no result...

thanks.
May 26 '08 #4
sicarie
4,677 Recognized Expert Moderator Specialist
So what is your question, and what have you tried?
May 27 '08 #5
RedSon
5,000 Recognized Expert Expert
So what is your question, and what have you tried?
Just for fun 170! is:

725741562 followed by 298 zeros, give or take. Or in notation its 7.25741562 × 10^306
May 27 '08 #6
JosAH
11,448 Recognized Expert MVP
Just because people can't comprehend the size of factorials, maybe Stirling's
approximation can be of any insight:

ln(n!) ~= n*ln(n)-n

Just plug in some values for n and play with your calculator ;-)

kind regards,

Jos
May 28 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
0
by: Refky Wahib | last post by:
Hi I need Technical Support I finished a Great project using .Net and SQL Server and .Net Mobile Control My Business case is to implement this Program to accept about 1 Million concurrent...
117
by: Peter Olcott | last post by:
www.halting-problem.com
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
2
by: Zongwen | last post by:
this problem happened after we upgrade our program from vc6.0 to vc.net2003 unmanaged code. Following are the sample code: float p, cpr = 3.4028234663852886e+038; p = (1.0f -...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.