Re: Can someone please explain - real numbers
- From: John Dough <nobody@xxxxxxxxxxxxxxx>
- Date: Thu, 09 Nov 2006 13:30:02 -0500
On Thu, 9 Nov 2006 10:57:13 +0100, "Maarten Wiltink"
<maarten@xxxxxxxxxxxxxxxxxx> wrote:
It took some work, but here's a program that demonstrates the problem:
var X: Real;
begin
X:=0.2; { To start the recurring fraction immediately }
while True do begin
X:=16*X;
X:=X-3;
end;
end.
Sixteen times 0.2 equals 3.2, subtracting 3 should leave us with the
original 0.2. Ad infinitum. Right?
After 16 iterations, X had become 0.25 on my computer.
On mine too.
Trying to figure it out by watching what happens to each iteration
right now by displaying it.
Take a look...
procedure TForm1.Button1Click(Sender: TObject);
var X: extended;
a: integer;
begin
memo1.Clear;
X := 0.2; { To start the recurring fraction immediately }
memo1.Lines.Add('X is equal to '+floattostrf(x,ffNumber,18,18));
for a := 1 to 16 do begin
X := 16 * x;
memo1.Lines.Add('16 * x is currently
'+floattostrf(x,ffnumber,18,18));
X := X-3;
memo1.Lines.Add('X-3 is currently
'+floattostrf(x,ffnumber,18,18));
end;
memo1.Lines.Add('X is equal to '+floattostrf(x,ffNumber,18,18));
end;
(Set the Memo's font to a fixed pitch for better display so that
everything lines up - I use Courier New, size 10).
I think I'll try to convince Intel to recall all Pentium processors
again. There seems to be an FMUL bug in them, too.
It's not an Intel problem. I just tried the exact same code on an AMD
Athlon XP and it gives the exact same results, bit for bit.
If it's not an Intel problem, the only reasonable explanations left
are the compiler and/or the IEEE standards.
.
- Follow-Ups:
- Re: Can someone please explain - real numbers
- From: Henry Bartlett
- Re: Can someone please explain - real numbers
- From: Maarten Wiltink
- Re: Can someone please explain - real numbers
- From: Sven Pran
- Re: Can someone please explain - real numbers
- References:
- Can someone please explain - real numbers
- From: Paul W
- Re: Can someone please explain - real numbers
- From: Paul W
- Re: Can someone please explain - real numbers
- From: Nicholas Sherlock
- Re: Can someone please explain - real numbers
- From: Paul W
- Re: Can someone please explain - real numbers
- From: John Dough
- Re: Can someone please explain - real numbers
- From: Chris Cheney
- Re: Can someone please explain - real numbers
- From: John Dough
- Re: Can someone please explain - real numbers
- From: Maarten Wiltink
- Can someone please explain - real numbers
- Prev by Date: Re: Can someone please explain - real numbers
- Next by Date: Re: HTML parser ? WAS: Parsing text from portal.
- Previous by thread: Re: Can someone please explain - real numbers
- Next by thread: Re: Can someone please explain - real numbers
- Index(es):