Sign in Join
Wiki copytemporary

Slash/de: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-<div style="float:left; margin: 0 10px 10px 0; padding:40px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">
2-
31/
4-
5-</div>
62
73## Division
84
95Der Schrägstrich `/` wird in [[Pascal/de|Pascal]] für Fliesskommazahlendivision verwendet. Soll eine Ganzzahldivision vorgenommen werden, so wird der Operator `div` verwendet.
106
117Siehe auch:
128
139- [[Div/de|div]]
1410- [[Round/de|round]]
1511- [[Trunc/de|trunc]]
1612- [[Mod/de|mod]]
1713
1814``` pascal
1915A := 3 / 4;
2016```
2117
2218Nach dieser Operation hält die Variable `A` den Wert `0.75` ([[Binary/de|binär]] normalisiert 1.1 E-1).
2319
2420Eine Division durch `0` kann mit folgenden `try`-Blöcken abgefangen werden:
2521
2622- [[Try/de|try]] … [[Finally/de|finally]]
2723- `try` … [[Except/de|except]]
2824
2925## Kommentar
3026
3127Verwendet man zwei Schrägstriche direkt hintereinander, kann man es für Kommentare brauchen. Ein Negativbeispiel (man kommentiert nicht, was direkt aus dem Quelltext ersichtlich ist, sondern *warum* man etwas tut).
3228
3329``` pascal
3430A := 3 / 4; // Dies ist eine Division mit reellen Zahlen.
3531```
3632
3733## Beispiel: *division by zero* abfangen
3834
3935Dieses Beispiel zeigt, wie man **division by zero** abfängt.
4036
4137``` pascal
4238program divZeroDemo(input, output, stderr);
4339
4440// ObjFPC mode for exceptions
4541{$mode objfpc}
4642
4743uses
4844 // make exception EDivByZero known
4945 sysutils;
5046
5147const
5248 dividend = 1.1;
5349
5450resourcestring
5551 enterDivisorPrompt = 'Bitte Divisor eingeben:';
5652 divisionOperationExceptionless = 'Es konnte dividiert werden.';
5753 zeroDivisionFailure = 'Fehler: Es wurde versucht durch 0 zu teilen.';
5854
5955var
6056 divisor, quotient: single;
6157
6258begin
6359 writeLn(enterDivisorPrompt);
6460 readLn(divisor);
6561
6662 try
6763 quotient := dividend / divisor;
6864 writeLn(divisionOperationExceptionless);
6965 except on EDivByZero do
7066 writeLn(zeroDivisionFailure);
7167 end;
7268end.
7369```
7470
7571Autor: Mathias
7672
7773---
7874*From the Free Pascal wiki, page "Slash/de", as it stood on 2022-08-06 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
7975Category: FPC/de
8076Category: Pascal/de
8177Category: Symbols/de

Back to history