Slash/de: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | - | ||
| 2 | - | ||
| 3 | 1 | / | |
| 4 | - | ||
| 5 | - | ||
| 6 | 2 | ||
| 7 | 3 | ## Division | |
| 8 | 4 | ||
| 9 | 5 | Der Schrägstrich `/` wird in [[Pascal/de|Pascal]] für Fliesskommazahlendivision verwendet. Soll eine Ganzzahldivision vorgenommen werden, so wird der Operator `div` verwendet. | |
| 10 | 6 | ||
| 11 | 7 | Siehe auch: | |
| 12 | 8 | ||
| 13 | 9 | - [[Div/de|div]] | |
| 14 | 10 | - [[Round/de|round]] | |
| 15 | 11 | - [[Trunc/de|trunc]] | |
| 16 | 12 | - [[Mod/de|mod]] | |
| 17 | 13 | ||
| 18 | 14 | ``` pascal | |
| 19 | 15 | A := 3 / 4; | |
| 20 | 16 | ``` | |
| 21 | 17 | ||
| 22 | 18 | Nach dieser Operation hält die Variable `A` den Wert `0.75` ([[Binary/de|binär]] normalisiert 1.1 E-1). | |
| 23 | 19 | ||
| 24 | 20 | Eine Division durch `0` kann mit folgenden `try`-Blöcken abgefangen werden: | |
| 25 | 21 | ||
| 26 | 22 | - [[Try/de|try]] … [[Finally/de|finally]] | |
| 27 | 23 | - `try` … [[Except/de|except]] | |
| 28 | 24 | ||
| 29 | 25 | ## Kommentar | |
| 30 | 26 | ||
| 31 | 27 | Verwendet 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). | |
| 32 | 28 | ||
| 33 | 29 | ``` pascal | |
| 34 | 30 | A := 3 / 4; // Dies ist eine Division mit reellen Zahlen. | |
| 35 | 31 | ``` | |
| 36 | 32 | ||
| 37 | 33 | ## Beispiel: *division by zero* abfangen | |
| 38 | 34 | ||
| 39 | 35 | Dieses Beispiel zeigt, wie man **division by zero** abfängt. | |
| 40 | 36 | ||
| 41 | 37 | ``` pascal | |
| 42 | 38 | program divZeroDemo(input, output, stderr); | |
| 43 | 39 | ||
| 44 | 40 | // ObjFPC mode for exceptions | |
| 45 | 41 | {$mode objfpc} | |
| 46 | 42 | ||
| 47 | 43 | uses | |
| 48 | 44 | // make exception EDivByZero known | |
| 49 | 45 | sysutils; | |
| 50 | 46 | ||
| 51 | 47 | const | |
| 52 | 48 | dividend = 1.1; | |
| 53 | 49 | ||
| 54 | 50 | resourcestring | |
| 55 | 51 | enterDivisorPrompt = 'Bitte Divisor eingeben:'; | |
| 56 | 52 | divisionOperationExceptionless = 'Es konnte dividiert werden.'; | |
| 57 | 53 | zeroDivisionFailure = 'Fehler: Es wurde versucht durch 0 zu teilen.'; | |
| 58 | 54 | ||
| 59 | 55 | var | |
| 60 | 56 | divisor, quotient: single; | |
| 61 | 57 | ||
| 62 | 58 | begin | |
| 63 | 59 | writeLn(enterDivisorPrompt); | |
| 64 | 60 | readLn(divisor); | |
| 65 | 61 | ||
| 66 | 62 | try | |
| 67 | 63 | quotient := dividend / divisor; | |
| 68 | 64 | writeLn(divisionOperationExceptionless); | |
| 69 | 65 | except on EDivByZero do | |
| 70 | 66 | writeLn(zeroDivisionFailure); | |
| 71 | 67 | end; | |
| 72 | 68 | end. | |
| 73 | 69 | ``` | |
| 74 | 70 | ||
| 75 | 71 | Autor: Mathias | |
| 76 | 72 | ||
| 77 | 73 | --- | |
| 78 | 74 | *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).* | |
| 79 | 75 | Category: FPC/de | |
| 80 | 76 | Category: Pascal/de | |
| 81 | 77 | Category: Symbols/de |
