Re: C ++ help!
- From: "Simon. (Zed Argh Seven)" <sj_bradleyspam@xxxxxxxxxxxxxxxx>
- Date: Sun, 26 Mar 2006 23:40:15 GMT
on Sun, 26 Mar 2006 19:02:35 +0100, SP <poyiads4@xxxxxxxxxxxx> wrote this
wisdom:
Alf P. Steinbach wrote:
* SP:
Hi all. I am working with a small prog that does some computations on
doubles and I am using a loop to calculate doubles up to an
approcimation. As soon as I reach a number of approximations, I get
1.#INFO as result
Be accurate. You don't get '1.#INFO'. Probably you get '1.#INF' or
some such, where 'INF' denotes 'infinity'.
and I think this means that the side next to the decimal point is too
large.
No, it means too large a number.
I am trying to think of a way for me to check and end my loop as soon
as I get to a point that gives me this result...
Any ideas???
Post code, be accurate.
OK. This is my function:
double Exponential::exponentialFunction(float x)
{
int count = 1;
int factorial = 1;
double y;
float number = x;
double result = exp(number);
while (fabs(y - result) > (10 * exp(-12)))
{
factorial *= count;
y += pow(x, count) / factorial;
printf("The %dth approximation of %f is: %lf \n", count, x, y);
count ++;
}
return y;
}
And when i run it, at the beginning i get normal approximations and then
for the rest is printed: 1.#INF00
At some point factorial *= count when count is zero
So next line you divide by zero so y is undefined (Infinity)
Then you try to print y
Put an if statment around the factorial to find out WHY count becomes zero and
when.
--
Simon.
'Be Seeing You.
Who is number one?
I will not be pushed, filed, stamped, indexed, briefed, de-briefed or numbered.
Registered Linux User #300464 Machine Id #188886
Linux Counter - http://counter.li.org/
Remove the s.p.a.m to reply
.
- References:
- C ++ help!
- From: SP
- Re: C ++ help!
- From: Alf P. Steinbach
- Re: C ++ help!
- From: SP
- C ++ help!
- Prev by Date: Re: Misuse of for
- Next by Date: Re: C ++ help!
- Previous by thread: Re: Misuse of for
- Next by thread: Re: C ++ help!
- Index(es):
Relevant Pages
|