Sign in Join
Wiki copytemporary

*: what changed

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

Title: *

OldNewLine
1+*
2+
3+## standard Pascal
4+
5+The symbol `*`, pronounced “asterisk”, is used in [[Pascal]] to
6+
7+- indicate multiplication of numbers, or
8+- form the intersection of [[Set|sets]].
9+
10+``` pascal
11+program asteriskDemo(input, output, stderr);
12+
13+type
14+ day = (monday, tuesday, wednesday,
15+ thursday, friday, saturday, sunday);
16+
17+var
18+ i: longint;
19+ n: real;
20+ m: set of day;
21+
22+begin
23+ // multiplication operator
24+ i := 6 * 7; // i becomes 42
25+ n := 6.0 * 7.0; // n becomes 42.0
26+
27+ // intersection operator
28+ m := [saturday, sunday] * [sunday, monday];
29+ // m is now {sunday}
30+end.
31+```
32+
33+## exponentiation
34+
35+Furthermore, in [[FPC]] the exponentiation operator consisting of two consecutive asterisks `**` exists. However, it is only [defined for variants](https://www.freepascal.org/docs-html/rtl/system/.op-power-variant-ariant-ariant.html) by the standard system unit, which requires a variant manager being installed. In order to actually use it with integers, one can [[Operator overloading|define]] it on their own:
36+
37+``` pascal
38+program exponentiation(input, output, stdErr);
39+
40+// make operator overloading available
41+{$mode objFPC}
42+
43+operator ** (const base: integer; const exponent: integer): integer;
44+begin
45+ if base <> 0 then
46+ begin
47+ result := trunc(exp(ln(base) * exponent));
48+ end;
49+end;
50+
51+begin
52+ writeLn(2 ** 10); // will print 1024
53+end.
54+```
55+
56+For readily available overloads, the [`math`](https://www.freepascal.org/docs-html/rtl/math/index.html) and [`matrix` unit](https://www.freepascal.org/docs-html/rtl/matrix/index.html) can be [[Uses|included]].
57+
58+## other appearances
59+
60+In Pascal's years of childhood computer systems did not necessarily knew the [[Comments|comment]] delimiting characters opening and closing curly brace `{ }`. To make block comments available on such systems an alternative syntax, the bigramms `(*` and `*)` are allowed, too, but they can't be interchanged willynilly: `(*` *has* to match a `*)`, and can *not* match a `}` even though it is closing a block comment, too.
61+
62+Also, if C like operators were allowed by the compiler directive [[sCoperator|{$COperator on}]], the short syntax for `i := i * n` reads `i *= n`. But by doing so, you leave the domain of Pascal. Your code technically, mathematically speaking becomes wrong.
63+
64+In [[ASCII]], the character code decimal `42` (or [[Hexadecimal|hexadecimal]] `2A`) is defined to be `*`.
65+
66+---
67+*From the Free Pascal wiki, page "*", as it stood on 2022-11-27 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).*
68+Category: Code

Back to history