Sign in Join
Wiki copytemporary

Slash: what changed

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

OldNewLine
1-<div style="float:right; margin: 0 25px 20px 0; padding:50px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">
2-
31/
42
5-</div>
6-
73A single slash, surrounded by non-slash characters is regarded as the division operator. Two consecutive slashes are regarded as comment introducers.
84
95## division
106
117The ASCII slash `/` is used in a [[Pascal]] [[Program|program]] to perform division (`∕` U+2215 “division slash”). The results are *always* real values. If you want to perform integer division the [[Div|div operator]] has to be used.
128
139``` pascal
1410A := 3 / 4;
1511```
1612
1713After this operation the [[Variable|variable]] `A` holds the value `0.75` (assuming `A` is declared as a real value [[Type|type]], otherwise the [[Compiler|compiler]] generates an incompatible type error).
1814
1915### related exceptions
2016
2117The value on the right side of the slash must not be zero, or a division by zero error occurs. In [[Compiler Mode|modes]] where [[Exceptions|exceptions]] are available (e.g. [[Mode ObjFPC|ObjFPC]] and [[Mode Delphi|Delphi]] mode) this condition can be caught by using a [[Try|try]] … [[Except|except]] [[Frame|frame]]. Otherwise a [[runtime error|run-time error]] occurs (RTE 200).
2218
2319``` pascal
2420program divZeroDemo(input, output, stderr);
2521
2622// ObjFPC mode for exceptions
2723{$mode objfpc}
2824
2925uses
3026 // make exception EDivByZero known
3127 sysutils;
3228
3329const
3430 dividend = 1.1;
3531
3632resourcestring
3733 enterDivisorPrompt = 'Enter divisor:';
3834 divisionOperationExceptionless = 'Division did not cause an exception.';
3935 zeroDivisionFailure = 'Error: Attempted to divide by zero.';
4036
4137var
4238 divisor, quotient: single;
4339
4440begin
4541 writeLn(enterDivisorPrompt);
4642 readLn(divisor);
4743
4844 try
4945 quotient := dividend / divisor;
5046 writeLn(divisionOperationExceptionless);
5147 except on EDivByZero do
5248 writeLn(zeroDivisionFailure);
5349 end;
5450end.
5551```
5652
5753> **Note:** Exception handling is expensive. A plain test whether the user input is non-zero would have been in the above example more sophisticated.
5854
5955## comment
6056
6157Two slashes back to back introduce [[Comments|comments]] till the [[End of Line|end of line]]. This is also known as “Delphi-style comment”.
6258
6359```delphi
6460while (buf^ in [' ', #9, #10]) do // kill separators
6561```
6662
67-<small>[example source](https://svn.freepascal.org/cgi-bin/viewvc.cgi/tags/release_3_0_4/rtl/inc/system.inc?view=markup#l1345)</small>
63+[example source](https://svn.freepascal.org/cgi-bin/viewvc.cgi/tags/release_3_0_4/rtl/inc/system.inc?view=markup#l1345)
6864
6965## see also
7066
7167- [[Round|round]]
7268- [[Trunc|trunc]]
7369
7470---
7571*From the Free Pascal wiki, page "Slash", as it stood on 2021-01-26 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).*

Back to history