Skip to content

Modulo Operator

IsaacShelton edited this page Mar 21, 2022 · 1 revision

% Operator

The % operator is used for performing the modulo operation on two numeric types.

1 % 2

Override

The % operator can be defined for non-numeric types or type combinations with the following:

func __modulus__(a $A, b $B) $C 

where $A, $B and $C are any valid types

See __modulus__ for more information.

Other Uses

A common usage of the % operator (for non-numeric types) is simple String substitution:

"Welcome %!" % "Isaac"

Allowed by these definitions:

func __modulus__(lhs POD String, rhs String) String
func __modulus__(lhs POD String, rhs int) String
func __modulus__(lhs POD String, rhs ptr) String
func __modulus__(lhs POD String, rhs bool) String
func __modulus__(lhs POD String, rhs $T~__primitive__) String
Clone this wiki locally