473,396 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

1.#INF00 problem while trying to calculate pi

I did my program to calculate pi but for some reason, every single time I run the program, screen says "1.#INF00":

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main (void)
  5. {
  6.     float a;
  7.     int i, x, b, c, d, e, f;
  8.     x=3;
  9.     a=1.0;
  10.     b=1;
  11.     c=4;
  12.     d=5;
  13.     e=1;
  14.     f=3;
  15.     for (i=1; i<=9999; i=i+1)
  16.     {
  17.         a=a*(x+((e*b)/(c*d*f)));
  18.         x=x+5;
  19.         b=b+2;
  20.         c=c+3;
  21.         d=d+3;
  22.         e=e+1;
  23.     }
  24.     printf("%f", a);
  25.     return 0;
  26. }
Sep 20 '13 #1
5 9700
weaknessforcats
9,208 Expert Mod 8TB
1.#INF00 is an IEEE floating point exception. There are several kinds of these. This one is a positive infinity and it means your float variable is not in floating point format.

That suggests your loop doesn't work.

I suggest you set a breakpoint at the start of your loop and step the loop to see if the variable a is still in floating point format. If you see a decimal number in your debugger, then a is still in float format. Otherwise, you will see the 1.#INF00.
Sep 20 '13 #2
Banfa
9,065 Expert Mod 8TB
I'm not sure where you got the formula from but it is very wrong

Consider ((e*b)/(c*d*f))

All variables are integers so arithmetic is integer based and they have the following characteristics

Initial
Variable Value Increment
b 1 2
c 4 3
d 5 3
e 1 1
f 3 0

Then for these values
c > b is always true
d > e is always true

Therefore (e*b) < (c*d*f) is always true* and since integer division is in operation ((e*b)/(c*d*f)) is always 0.


* Actually this isn't quite true because towards the end of the iteration (c*d*f) actually wraps (gets bigger than an integer can hold) and on my machine this results in a negative number but the absolute value of this number is always bigger than (e*b) but that is a fluke.

Since ((e*b)/(c*d*f)) is always 0 your calculation becaomes

Expand|Select|Wrap|Line Numbers
  1.     x=3;
  2.     a=1.0;
  3.  
  4.     for (i=1; i<=9999; i=i+1)
  5.     {
  6.         a=a*x;
  7.         x=x+5;
  8.     }
  9.  
x increments by 5 every time it is getting larger all the time a is getting exponentially larger all the time. It calculates

3 * 8 * 13 * 18 * ... * 49983 * 49988 * 49993 * 49998

This is neither PI nor does it fit into a float.


In fact a takes the value 1.#INF on the 130th iteration of the loop, on the 129th iteration it had the value 7.01924e306, at this point x had a value of 648.
Sep 20 '13 #3
How could I change my program in order to obtain an aproximation to pi? because I need to do 10 similar programs and I got most of the ideas from the webpage http://mathworld.wolfram.com/PiFormulas.html, but so far I've only been able to program Leibniz's
Sep 20 '13 #4
Banfa
9,065 Expert Mod 8TB
Well you need to make sure you get the logic of your implementation correct. It is not clear to me which of those 130+ formulas you where trying to implement.
Sep 20 '13 #5
You are absolutely right, my apologies. I was trying to do Beeler's, Sloane's and Wallis'. The program I previously posted was an attempt of Beeler's.
Sep 20 '13 #6

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

Similar topics

5
by: Ravi Shankar | last post by:
Hi, I get the below error while I press F5 from Microsoft Visual Studio .NET Enterprise Architect IDE. This doesn't allow me to debug the application. But I am able to launch any other C#...
2
by: H. | last post by:
Hi, I have error while i start to run my ASP.NET application on visual studio 2003. when i press F5, there is error message " Error while trying to run the project. Unable to start debugging on...
3
by: Vinod | last post by:
Hi Team, I am getting an Error Msg while trying to Execute my ASP.Net Application Error is, "Error while trying to run project : Unable to start debugging on the web server. The server does...
11
by: Claude seraphin | last post by:
I'am having this message while trying to rune my asp.net app on win3k server. I have set debug="true" in <compilation section in my web.config . Can anyone help me? Thanks in advance
4
by: a | last post by:
When executing the ASP.NET app, I get: "Error while trying to run a project: Unable to start debugging on the web server. A debugger is already attached. Would you like to disable future...
1
by: Jon | last post by:
Hi all i encountered a problem will trying to run a C# Project (ASP.net Web Application). When i click 'start without debugging', it throws me an error *******************************************...
13
by: Kris Desmadryl | last post by:
Hi all, I create a new asp project, with just one button on the startup form but when I run I always get a messagebox with the error : "Error while trying to run project." No more information....
7
by: Kris Desmadryl | last post by:
Hi all, I create a new asp project, with just one button on the startup form but when I run I always get a messagebox with the error : "Error while trying to run project." That's all what I see...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
2
by: Otis Monroe | last post by:
#include <iostream> #include <iomanip> #include <string> using namespace std; int main() { //declare variables string name = " ";
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.