Difference between revisions of "*"
(de-stub page) |
|||
Line 1: | Line 1: | ||
{{*}} | {{*}} | ||
− | <div style="float: | + | <div style="float:right; margin: 0 25px 20px 0; padding:50px; font-size:500%; font-family: Georgia; background-color: #f9f9f9; border: 2px solid #777777;">*</div> |
− | The symbol | + | == standard Pascal == |
+ | The symbol <syntaxhighlight lang="pascal" enclose="none">*</syntaxhighlight>, pronounced “asterisk”, is used in Pascal to | ||
+ | * indicate multiplication of numbers, or | ||
+ | * form the intersection of [[Set|sets]]. | ||
+ | |||
+ | <syntaxhighlight lang="pascal" highlight="13-15,17,18"> | ||
+ | program asteriskDemo(input, output, stderr); | ||
+ | |||
+ | type | ||
+ | day = (monday, tuesday, wednesday, | ||
+ | thursday, friday, saturday, sunday); | ||
+ | |||
+ | var | ||
+ | i: longint; | ||
+ | n: real; | ||
+ | m: set of day; | ||
+ | |||
+ | begin | ||
+ | // multiplication operator | ||
+ | i := 6 * 7; // i becomes 42 | ||
+ | n := 6.0 * 7.0; // n becomes 42.0 | ||
+ | |||
+ | // intersection operator | ||
+ | m := [saturday, sunday] * [sunday, monday]; | ||
+ | // m is now {sunday} | ||
+ | end. | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == exponentiation == | ||
+ | Furthermore, in [[FPC]] the exponentiation operator consisting of two consecutive asterisks <syntaxhighlight lang="pascal" enclose="none">**</syntaxhighlight> exists. | ||
+ | However, it isn't defined for any type by the standard system unit. | ||
+ | Instead you have the chance to overload it on your own. | ||
+ | |||
+ | <syntaxhighlight lang="pascal" highlight="6-9,12"> | ||
+ | program exponentiation(input, output, stderr); | ||
+ | |||
+ | // make operator overloading available | ||
+ | {$mode objfpc} | ||
+ | |||
+ | operator ** (const base: integer; const exponent: integer): integer; | ||
+ | begin | ||
+ | result := trunc(exp(ln(base) * exponent)); | ||
+ | end; | ||
+ | |||
+ | begin | ||
+ | writeLn(2 ** 10); // will print 1024 | ||
+ | end. | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | For readily available overloads, the {{Doc|package=RTL|unit=math|text=<syntaxhighlight lang="pascal" enclose="none">math</syntaxhighlight>}} and {{Doc|package=RTL|unit=math|text=<syntaxhighlight lang="pascal" enclose="none">matrix</syntaxhighlight> unit}} can be [[Uses|included]]. | ||
+ | |||
+ | == other appearances == | ||
+ | In Pascal's years of childhood computer systems did not necessarily knew the comment delimiting characters opening and closing curly brace <syntaxhighlight lang="pascal" enclose="none">{ }</syntaxhighlight>. | ||
+ | To make block comments available on such systems an alternative syntax, the bigramms <syntaxhighlight lang="pascal" enclose="none">(*</syntaxhighlight> and <syntaxhighlight lang="pascal" enclose="none">*)</syntaxhighlight> are allowed, too, but they can't be interchanged willynilly: | ||
+ | <syntaxhighlight lang="pascal" enclose="none">(*</syntaxhighlight> ''has'' to match a <syntaxhighlight lang="pascal" enclose="none">*)</syntaxhighlight>, and can ''not'' match a <syntaxhighlight lang="pascal" enclose="none">}</syntaxhighlight> even though it is closing a block comment, too. | ||
+ | |||
+ | Also, if C like operators were allowed by the compiler directive [[sCoperator|<syntaxhighlight lang="pascal" enclose="none">{$COperator on}</syntaxhighlight>]], the short syntax for <syntaxhighlight lang="pascal" enclose="none">i := i * n</syntaxhighlight> reads <syntaxhighlight lang="pascal" enclose="none">i *= n</syntaxhighlight>. | ||
+ | But by doing so, you leave the domain of Pascal. | ||
+ | Your code technically, mathematically speaking becomes wrong. | ||
− | |||
{{Symbols}} | {{Symbols}} | ||
− | + | [[Category:Code]] | |
− |
Revision as of 01:02, 13 April 2018
│
English (en) │
suomi (fi) │
français (fr) │
русский (ru) │
standard Pascal
The symbol *
, pronounced “asterisk”, is used in Pascal to
- indicate multiplication of numbers, or
- form the intersection of sets.
program asteriskDemo(input, output, stderr);
type
day = (monday, tuesday, wednesday,
thursday, friday, saturday, sunday);
var
i: longint;
n: real;
m: set of day;
begin
// multiplication operator
i := 6 * 7; // i becomes 42
n := 6.0 * 7.0; // n becomes 42.0
// intersection operator
m := [saturday, sunday] * [sunday, monday];
// m is now {sunday}
end.
exponentiation
Furthermore, in FPC the exponentiation operator consisting of two consecutive asterisks **
exists.
However, it isn't defined for any type by the standard system unit.
Instead you have the chance to overload it on your own.
program exponentiation(input, output, stderr);
// make operator overloading available
{$mode objfpc}
operator ** (const base: integer; const exponent: integer): integer;
begin
result := trunc(exp(ln(base) * exponent));
end;
begin
writeLn(2 ** 10); // will print 1024
end.
For readily available overloads, the math
and matrix
unit can be included.
other appearances
In Pascal's years of childhood computer systems did not necessarily knew the 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.
Also, if C like operators were allowed by the compiler directive {$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.
single characters |
|
character pairs |
|