Re: C ++ help!



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
.



Relevant Pages

  • Re: C ++ help!
    ... doubles and I am using a loop to calculate doubles up to an ... at the beginning i get normal approximations and then ... unless you assume it is zero. ... How many 'good' values do you get before INF? ...
    (comp.programming)
  • Re: C ++ help!
    ... doubles and I am using a loop to calculate doubles up to an ... approcimation. ... at the beginning i get normal approximations and then ... Registered Linux User #300464 Machine Id #188886 ...
    (comp.programming)
  • Re: On writing negative zero - with or without sign
    ... I sure hope that a program can represent an exact zero. ... programs represent, manipulate, and produce approximations. ... (which is not what floating point does) ...
    (comp.lang.fortran)
  • Re: On writing negative zero - with or without sign
    ... number of fractional digits, but these digits are all zeroes after ... the values to indicate which side of absolute zero the values lies. ... are two different approximations to zero. ... It's *less* exact. ...
    (comp.lang.fortran)
  • Re: Strange result in Excel 2000
    ... None of your numbers have exact binary representations, and hence must be approximated. ... The binary approximations to the numbers involved in the final subtraction are ... What they did is to assume that if a final subtraction involves two numbers that are equal to at least 15 decimal digits, then Excel will arbitrarily zero the result on the assumption that the non-zero difference is residue from binary approximations. ...
    (microsoft.public.excel)