Accuracy in float and double (in C)

From: Steve (carvegio_at_gmail.com)
Date: 02/25/05


Date: Fri, 25 Feb 2005 01:19:34 +0000 (UTC)

Hello, I am trying to solve this problem in c and I am having a great
deal of problem trying to figure out what is going on.

I was hoping someone could please explain it to me.

It involves a three term recurrence x[i]=A*x[i-1]+B*x[i-2]
with x[0]=x[1]=...x[n]=1/3 (0.33333r).

A is (double)(100001+1), B is (double)(-100001)

When I work this out using float I get perfectly accurate answers
but when I change type to double, my answers are horribly wrong
and get worse and worse as we progress, and similarily with long
double.

I don't understand why, I know floating point can not represent
1/3 accurately. But I would of thought that float would have the
same problem storing it as float, and cause bad results.
But this is not the case.

Also if we change the recurrence to
x[i]=(A-1)*x[i-1]+B*x[i-2]+x[i-1] we get perfect answers, and I
dont understand how this is so different to what we had before,
just taking one part of A outside.

Hope someone can help

Thanks



Relevant Pages

  • Re: Why wont be
  • background span the whole background?
    ... Ive just noticed I am getting the dreaded horizontal scroll bar ... I dont have anything set to over 100% in width - what ... Im using an inline list for my horizontal navbar items with the right ... float: left, and then you can set the height on the to 23px. ...
    (comp.infosystems.www.authoring.stylesheets)
  • Re: Accuracy in float and double (in C)
    ... >but when I change type to double, ... But I would of thought that float would have the ... you have a linear recurrence which is unstable. ... but in evaluating this numerically there will be roundoff errors ...
    (sci.math.num-analysis)
  • Re: Compiler Code Optimization
    ... Roberto Della Pasqua wrote: ... > others dont' use this check that delphi.net open by deafult ...
    (borland.public.delphi.language.basm)
  • Re: [PHP] problem with string & floats in PHP
    ... Arbitrary Precision Mathematics Functions. ... I dont understand why. ... In the documentation it is clear that this kind ... of data should be considerer float, ...
    (php.general)
  • Re: problem with string & floats in PHP
    ... All you need is to cast it (float) to float, (int) to int. ... I have read the php documentation ... I dont understand why. ...
    (php.general)