Autor Beitrag
Flamefire
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 13.06.07 18:43 
ich hab ne konstant so deklariert:

const myVersion:Single=1.10000000000;

aber wenn ich jz z.b.: 1.1-myVersion rechne, kommt nicht 0 raus sondern sowas wie 0,000000000884149

wie kann ich das beheben?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 13.06.07 18:49 
Mit Float-Typen gar nicht.

_________________
We are, we were and will not be.
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Mi 13.06.07 18:55 
na toll...
dann muss ich mich wo damit abgeben dass 1.1-1.1 nicht 0 ist?
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 13.06.07 19:01 
Du kannst Version und Suberversion getrennt in Integern speichern und diese überprüfen. Dass 1.1-1.1 ungleich 0 ist liegt an der Ungenauigkeit bei der Darstellung von Fließkommazahlen im Rechner. Du kannst auf < 0.00000001 abfragen, aber bei einer Versionsabfrage wäre das irgendwie komisch.

_________________
We are, we were and will not be.
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 765
Erhaltene Danke: 130



BeitragVerfasst: Mi 13.06.07 19:07 
Bei Single speichert Delphi die Zahl in 4 Byte ab, da geht es nicht genauer.
Mit Double werden 8 Byte verwendet, da ist die Abweichung nur noch 8,87961579265628E-17.
Rechnet man mit Extended, die in Delphi 10 Byte benötigen, wird eine Differenz von 0 angezeigt. Wenn Du also 1.1 eingibst, scheint Delphi intern mit Extended zu rechnen.

ub60
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Do 14.06.07 06:30 
Dazu einen Artikel von Luckie:
www.michael-puff.de/...13_Fliesskomma.shtml

Aber wieso brauchst du so genaue Zahlen für eine Versionsüberprüfung?

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 14.06.07 07:19 
user profile iconFlamefire hat folgendes geschrieben:
ich hab ne konstant so deklariert:

const myVersion:Single=1.10000000000;

aber wenn ich jz z.b.: 1.1-myVersion rechne, kommt nicht 0 raus sondern sowas wie 0,000000000884149

wie kann ich das beheben?


mit folgendem
ausblenden Delphi-Quelltext
1:
if Abs(1.1-myVersion)<1e-06 then //...					

kannst Du das Problem beheben, wobei 1e-06 erstmal reichen sollte, wenn mehr Stellen hinzukommen, einfach anpassen!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Fr 15.06.07 10:08 
ok danke...
ich rechne mit der versionsnummer...darum...
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Fr 15.06.07 10:42 
Du kannst auch einen ganzzahligen Wert für deine Versionsnummer nehmen und damit rechnen. Wenn man die Version als Hex-Wert kodiert geht das ganz prächtig:

Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
const
   VersionShort = $0102; //Version 1.2
   VersionLong = $01020304; //Version 1.2.3.4


Beste Grüße
Tastaro
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Fr 15.06.07 10:44 
ok...super idee...dumm muss man sein *g*
:oops: :oops: :oops:
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Fr 15.06.07 11:41 
Was spricht gegen einen String als Versionsnummer? Ach, er will ja 'rechnen' :gruebel:

_________________
Na denn, dann. Bis dann, denn.
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Fr 15.06.07 14:43 
user profile iconalzaimar hat folgendes geschrieben:
Was spricht gegen einen String als Versionsnummer? Ach, er will ja 'rechnen' :gruebel:

Jo, nur wozu braucht man das? Ich mache einfach String-Vergleiche, genau wegen der Rechenproblemen. Wenn die lokale Version anders ist, als die auf dem Server, muss ein Update gemacht werden, fertig. Normalerweise lädt man ja keine ältere Version auf den Server ;)
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Fr 15.06.07 17:52 
es sei denn die versionsnummer wird für eine verschlüsselung benutzt ^^
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Fr 15.06.07 18:12 
user profile iconFlamefire hat folgendes geschrieben:
es sei denn die versionsnummer wird für eine verschlüsselung benutzt ^^

StrToFloat oder StrToFloatDef?

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
Flamefire Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1207
Erhaltene Danke: 31

Win 10
Delphi 2009 Pro, C++ (Visual Studio)
BeitragVerfasst: Fr 15.06.07 19:57 
gleiches problem s. oben...