Difference between revisions of "*"
m (→exponentiation: fix link) |
|||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 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;">*</div> | <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> | ||
== standard Pascal == | == standard Pascal == | ||
− | The symbol <syntaxhighlight lang="pascal" | + | The symbol <syntaxhighlight lang="pascal" inline>*</syntaxhighlight>, pronounced “asterisk”, is used in [[Pascal]] to |
* indicate multiplication of numbers, or | * indicate multiplication of numbers, or | ||
* form the intersection of [[Set|sets]]. | * form the intersection of [[Set|sets]]. | ||
Line 34: | Line 32: | ||
== exponentiation == | == exponentiation == | ||
− | Furthermore, in [[FPC]] the exponentiation operator consisting of two consecutive asterisks <syntaxhighlight lang="pascal" | + | Furthermore, in [[FPC]] the exponentiation operator consisting of two consecutive asterisks <syntaxhighlight lang="pascal" inline>**</syntaxhighlight> exists. |
− | However, it | + | However, it is only {{Doc|package=RTL|unit=system|identifier=.op-power-variant-ariant-ariant|text=defined for variants}} 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: | |
− | + | <syntaxhighlight lang="pascal" highlight="6-12,15"> | |
− | <syntaxhighlight lang="pascal" highlight="6- | + | program exponentiation(input, output, stdErr); |
− | program exponentiation(input, output, | ||
// make operator overloading available | // make operator overloading available | ||
− | {$mode | + | {$mode objFPC} |
operator ** (const base: integer; const exponent: integer): integer; | operator ** (const base: integer; const exponent: integer): integer; | ||
begin | begin | ||
− | result := trunc(exp(ln(base) * exponent)); | + | if base <> 0 then |
+ | begin | ||
+ | result := trunc(exp(ln(base) * exponent)); | ||
+ | end; | ||
end; | end; | ||
Line 54: | Line 54: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | For readily available overloads, the {{Doc|package=RTL|unit=math|text=<syntaxhighlight lang="pascal" | + | For readily available overloads, the {{Doc|package=RTL|unit=math|text=<syntaxhighlight lang="pascal" inline>math</syntaxhighlight>}} and {{Doc|package=RTL|unit=matrix|text=<syntaxhighlight lang="pascal" inline>matrix</syntaxhighlight> unit}} can be [[Uses|included]]. |
== other appearances == | == other appearances == | ||
− | In Pascal's years of childhood computer systems did not necessarily knew the [[Comments|comment]] delimiting characters opening and closing curly brace <syntaxhighlight lang="pascal" | + | In Pascal's years of childhood computer systems did not necessarily knew the [[Comments|comment]] delimiting characters opening and closing curly brace <syntaxhighlight lang="pascal" inline>{ }</syntaxhighlight>. |
− | To make block comments available on such systems an alternative syntax, the bigramms <syntaxhighlight lang="pascal" | + | To make block comments available on such systems an alternative syntax, the bigramms <syntaxhighlight lang="pascal" inline>(*</syntaxhighlight> and <syntaxhighlight lang="pascal" inline>*)</syntaxhighlight> are allowed, too, but they can't be interchanged willynilly: |
− | <syntaxhighlight lang="pascal" | + | <syntaxhighlight lang="pascal" inline>(*</syntaxhighlight> ''has'' to match a <syntaxhighlight lang="pascal" inline>*)</syntaxhighlight>, and can ''not'' match a <syntaxhighlight lang="pascal" inline>}</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" | + | Also, if C like operators were allowed by the compiler directive [[sCoperator|<syntaxhighlight lang="pascal" inline>{$COperator on}</syntaxhighlight>]], the short syntax for <syntaxhighlight lang="pascal" inline>i := i * n</syntaxhighlight> reads <syntaxhighlight lang="pascal" inline>i *= n</syntaxhighlight>. |
But by doing so, you leave the domain of Pascal. | But by doing so, you leave the domain of Pascal. | ||
Your code technically, mathematically speaking becomes wrong. | Your code technically, mathematically speaking becomes wrong. | ||
+ | |||
+ | In [[ASCII]], the character code decimal <syntaxhighlight lang="pascal" inline>42</syntaxhighlight> (or [[Hexadecimal|hexadecimal]] <syntaxhighlight lang="pascal" inline>2A</syntaxhighlight>) is defined to be <syntaxhighlight lang="pascal" inline>*</syntaxhighlight>. | ||
{{Symbols}} | {{Symbols}} | ||
[[Category:Code]] | [[Category:Code]] |
Latest revision as of 16:10, 27 November 2022
│
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 is only defined for variants by the standard system unit, which requires a variant manager being installed.
In order to actually use it with integers, one can define it on their own:
program exponentiation(input, output, stdErr);
// make operator overloading available
{$mode objFPC}
operator ** (const base: integer; const exponent: integer): integer;
begin
if base <> 0 then
begin
result := trunc(exp(ln(base) * exponent));
end;
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.
In ASCII, the character code decimal 42
(or hexadecimal 2A
) is defined to be *
.
single characters |
|
character pairs |
|