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