Autor Beitrag
madmat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Sa 29.05.04 17:16 
Hallo zusammen,

ich habe ein Programm geschrieben das diverse mathemtische Operationen ausführt.
Wie kann ich vor der Ausgabe prüfen ob eine Variable den Integer Bereich verlässt um eine Fehlermeldung auszugeben ? Zz siehts so aus das das Programm beim grossen Zahlen irgendwelche Phantasiewerte entwickelt, was dann natürlich reichlich sinnlos ist...

Vielen Dank...

_________________
mfg
madmat
Life is what happens while you ´re making other plans
adler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 511

Windows XP
Delphi 05 Pers
BeitragVerfasst: Sa 29.05.04 18:44 
Phantasiezahlen?
Das glaube ich net! ;)

Wie wärs wenn du single als variablentyp nimmst? :-/
Oder LongInt

_________________
Wo's nix zu gucken gibt, gibts vielleicht was zu hören.
madmat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mo 31.05.04 08:24 
naja, also bei 10.000.000.000 als eingabewert wird die variable mit zb: 1.410.065.408 belegt...und single und long int verschieben das problem ja nur nach oben.
gibts da keine abfangmethode ?

_________________
mfg
madmat
Life is what happens while you ´re making other plans
adler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 511

Windows XP
Delphi 05 Pers
BeitragVerfasst: Mo 31.05.04 08:56 
klar, wenn du weißt wie weit ein Integer geht... glaube 2^32 oder sowas ^^
Kannste ja mal testen, dann machste einfach ne if-abfrage!
If variable > ende then
showmessage('fehler');

_________________
Wo's nix zu gucken gibt, gibts vielleicht was zu hören.
madmat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mo 31.05.04 09:08 
hmm...ja, ok. die variante hab ich schon umgesetzt, dachte da gibts evtl. was eleganteres ;)
trotzdem danke !

_________________
mfg
madmat
Life is what happens while you ´re making other plans
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: Mo 31.05.04 10:01 
Gibt auch was eleganteres. Allerdings kannst du dann erst danach prüfen, ob es zu einem Überlauf kam. Der Prozessor setzt in so einem Fall das Overflow-Flag. Wenn du dem Compiler mitteilst, dass er diese beachten soll (Compilerschalter Q bzw. OVERFLOWCHECKS), erstellt er eine Exception im Falle eines Überlaufs, die du abfangen kannst.

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind
madmat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mo 31.05.04 17:42 
ok, danke. *F1drück*
werde mich mal dahingehend belesen...
:)

_________________
mfg
madmat
Life is what happens while you ´re making other plans
madmat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mo 31.05.04 19:16 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
{$OVERFLOWCHECKS ON} 
try
    E:=rechnung;
    except
    on E: EIntOverflow do
        ShowMessage('Integerbereich verlassen');
 end;


das wars was ich suchte....

Moderiert von user profile iconPeter Lustig: Delphi-Tags hinzugefügt.

_________________
mfg
madmat
Life is what happens while you ´re making other plans