Autor Beitrag
Visum
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 106



BeitragVerfasst: Do 09.09.04 19:53 
Hi,
ich hab grad ein etwas komisches Problem, und zwar führe ich folgenden Code aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
p:=0;
repeat
 p:=p+dp; // dp war bei mir 0.0025
 label9.Caption:=floattostr(p);
until p>=1;

klingt nicht aufregend, allerdings ist die ausgabe in label9 etwas komisch, denn da kommen werte raus, die garnicht durch 0.0025 teilbar sind (etwa 1.0024999).
Wo liegt da der (rundungs?)fehler? Oder ist mein rechner zu "dumm" dafür?

freue mich über antworten
visum

_________________
Was blubbert kommt in den Teich!
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Do 09.09.04 20:20 
Die Aufklärung

Gruß,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 09.09.04 20:25 
Ist ein Problem der internen Darstellung der Zahlen im Prozessor.

Kleiner Tipp:
Geh mal in Excel, schreib in 10 Zellen untereinander 0.1 rein und bilde die Summe. Zieh von diesem Ergebnis 1 ab ...
Ergebnis: 10 * 0.1 <> 1!!!
Zur Erklärung empfehle ich dir das Interne-Speicher-Format für Zahlen anzugucken.
Um das Problem zu beheben würde ich dir empfehlen D := D + P * DP; zu rechnen und so viel wie möglich mit Integern zu rechnen (oder Zahlen, die sich ohne Rundung\Probleme als Fließkommazahlen darstellen lassen).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.