Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the multiplication operator documented for sets?

Tags:

set

delphi

I noticed this block of code today and was wondering if these type of operations are documented somewhere and why it was done this way (Performance, etc).

var
  Shift: TShiftState
begin
  if [ssShift, ssCtrl] * Shift <> [] then
  begin
    ...
  end;
end;

It looks to me from my testing and just looking at the code like this is checking if Shift contains either ssShift or ssCtrl. Is this documented behavior or is it just leveraging the fact that the set is actually stored as an integer internally?

like image 230
Graymatter Avatar asked Aug 04 '16 20:08

Graymatter


People also ask

Which is the multiplication operator?

The * (multiplication) operator yields the product of its operands. The operands must have an arithmetic or enumeration type. The result is not an lvalue. The usual arithmetic conversions on the operands are performed.

Which operator is used to multiply in Python?

Using the * Operator in Python The * operator is used to multiply numeric values in Python.

How do you write multiplication in Javascript?

An asterisk ( * ) is used to represent the multiplication operator.

How do you multiply in code?

The multiplication assignment operator ( *= ) multiplies a variable by the value of the right operand and assigns the result to the variable.


1 Answers

That's not the multiplication operator when used with sets; it's the intersection operator. This is documented, and has been since pre-Delphi days. See Expressions, particularly the section on set operations. They're the standard mathematical operators for union, intersection, sub- and super-sets, equality, inequality, and membership.

Here's a summary of the table from the docs:

Operator  Operation     Operand Types  Result Type  Example  
--------  ---------     -------------  -----------  -------
+          union        set            set          Set1 + Set2 
-          difference   set            set          S - T 
*          intersection set            set          S * T 
<=         subset       set            Boolean      Q <= MySet 
>=         superset     set            Boolean      S1 >= S2 
=          equality     set            Boolean      S2 = MySet 
<>         inequality   set            Boolean      MySet <> S1 
in         membership   ordinal, set   Boolean      A in Set1 
like image 74
Ken White Avatar answered Oct 20 '22 10:10

Ken White