suve

awful: function: mod

Declaration

mixed :mod ( mixed &ARG , … )
mixed :% ( mixed &ARG , … )

Summary

Takes any number of arguments. Performs modulo operarion between the rightmost pair of elements, then the second-rightmost, et cetera. Divides the value of the left element by the value of right one and assigns the division remainder to the left element. Note that references will modify the values of variables.
Returns a copy of the value the leftmost argument ended up with.

Modulo rules

The table below contains rules for moduloing values. Note that these rules are non-symmetrical; swapping the values may yield a different result. The row contains the type of the first (left) value in pair, while the column contains the type of the second (right) value in pair.

NIL bool bin oct int hex float string array dict
NIL Arithmetics on NIL values have no effect.
bool No effect.
bin Number is set to 0. Number is set to 0. No type juggling needed. Float is NOT truncated for this operation. String is converted to number (with regard to base). Moduloes by the number of entries in structure.
oct
int
hex
float Float is set to 0.0. Float is set to 0.0. No type juggling needed. String is converted to float. Moduloes by number of entries in structure.
string No effect.
array Modulo is performed on each structure element separately. Modulo is performed between keys present in both structures.
dict

Example

# :mod example.
:set &NUM i20
:set &D :div $NUM s'3'
:set &M :mod $NUM s'3'
:writeln s'NUM = ' $D s' * 3 + ' $M

wikipage modified on 2014/0601/2317