Div/fi: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | `Div` on sellainen jakolasku, jossa murto-osa (jakojäännös) hylätään. Lauseke `a div b` palauttaa kokonaisluvun kahden kokonaisluvun jakamisen tuloksesta. Tämä on toisin kuin ilmaisu `a / b`, joka palauttaa [[Real|reaaliluvun]] tuloksena. | |
| 2 | 2 | ||
| 3 | 3 | Ilmaisun molemmilla puolilla `div`:n on oltava kokonaisluvullinen tyyppi. Reaalilukutyyppisen operandin käyttäminen `div`in kanssa johtaa käännösaikaiseen virheeseen: | |
| 4 | 4 | ||
| 5 | - | ||
| 5 | + | ```text | |
| 6 | + | Error: Operator is not overloaded: […] | |
| 7 | + | ``` | |
| 6 | 8 | ||
| 7 | 9 | Jos halutaan saada kokonaislukutuloksen reealilukuisella operandilla niin käytä [`trunc`](https://www.freepascal.org/docs-html/rtl/system/trunc.html) tai [`round`](https://www.freepascal.org/docs-html/rtl/system/round.html) funktiota [[Slash|/ operator]] kanssa. | |
| 8 | 10 | ||
| 9 | 11 | Seuraavassa esimerkissä nähdään, mitä `div` tekee | |
| 10 | 12 | ||
| 11 | 13 | ``` pascal | |
| 12 | 14 | program divDemo(input, output, stderr); | |
| 13 | 15 | ||
| 14 | 16 | var | |
| 15 | 17 | i: shortInt; | |
| 16 | 18 | j: shortInt; | |
| 17 | 19 | q: qWord; | |
| 18 | 20 | r: qWord; | |
| 19 | 21 | ||
| 20 | 22 | begin | |
| 21 | 23 | i := 16; | |
| 22 | 24 | j := 3; | |
| 23 | 25 | q := 1000; | |
| 24 | 26 | r := 300; | |
| 25 | 27 | ||
| 26 | 28 | writeLn(i div j); | |
| 27 | 29 | writeLn(i / j); | |
| 28 | 30 | writeLn(q div r); | |
| 29 | 31 | writeLn(q / r); | |
| 30 | 32 | end. | |
| 31 | 33 | ``` | |
| 32 | 34 | ||
| 33 | 35 | Ulostulona saadaan: | |
| 34 | 36 | ||
| 35 | 37 | ``` bash | |
| 36 | 38 | $ ./divDemo | |
| 37 | 39 | 5 | |
| 38 | 40 | 5.3333333333333330E+000 | |
| 39 | 41 | 3 | |
| 40 | 42 | 3.3333333333333335E+000 | |
| 41 | 43 | ``` | |
| 42 | 44 | ||
| 43 | 45 | ## Katso myös | |
| 44 | 46 | ||
| 45 | 47 | - [[Mod|mod]] – jakojäännös (kokonaisluvuista). | |
| 46 | 48 | - [[Trunc|trunc]] – katkaisee kokonaisosan reaaliluvusta. | |
| 47 | 49 | - [[Round|round]] – pyöristää reaaliluvun kokonaisluvuksi. | |
| 48 | 50 | - [`math.divmod`](https://www.freepascal.org/docs-html/rtl/math/divmod.html) – palauttaa molemmat kokonaisosan ja jakojäännöksen. | |
| 49 | 51 | ||
| 50 | 52 | --- | |
| 51 | 53 | *From the Free Pascal wiki, page "Div/fi", 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).* |
