Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Konstante ist nicht konstant? (https://www.delphipraxis.net/73938-konstante-ist-nicht-konstant.html)

xZise 25. Jul 2006 21:14


Konstante ist nicht konstant?
 
Warum ist Wert 1 auf einmal so krum?
Delphi-Quellcode:
const
  MONEY: array[1..26] of Single = (0.01, 0.20, 0.50, 1, 5, 10, 20, 50, 100, 200, 300, 400, 500,
                                   1000, 2500, 5000, 7500, 10000, 12500, 15000, 20000, 25000,
                                   50000, 100000, 150000, 250000);
Ergebnis:
Zitat:

Money[MoneyBag[sb.Tag]]: 0,0099999997765
Warum passiert das einfach so?

SirThornberry 25. Jul 2006 21:15

Re: Konstante ist nicht konstant?
 
Weil eine Gleitkommazahl nur ein näherungswert ist. Such einfach mal danach wie solche Datentypen aufgebaut sind.

MaBuSE 26. Jul 2006 09:15

Re: Konstante ist nicht konstant?
 
Zitat:

Zitat von SirThornberry
Weil eine Gleitkommazahl nur ein näherungswert ist. Such einfach mal danach wie solche Datentypen aufgebaut sind.

Gleitkommazahlen werden in eine Mantisse und einen Exponent aufgeteilt.

Suche mal nach Hier im Forum suchenMantisse in der DP und Du wirst einige Beiträge finden.
(Unter anderem auch ein Codeschnipsel von mir, das Dir zeigt wie Die Zahl im Speicher abgelegt ist.)

Hier ist ein PDF das das Thema ausführlich behandelt:
http://www-nw.uni-regensburg.de/~.br...t/realform.pdf

Ich hoffe diese Infos helfen Dir weiter

xZise 26. Jul 2006 10:41

Re: Konstante ist nicht konstant?
 
Schade das das so ist ;) Aber wenn ich den Datentyp ändere (Single > Extended) dann funktionierts wieder ^^


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz