suve

awful: function: mul

Declaration

mixed :mul ( mixed &ARG , … )
mixed :* ( mixed &ARG , … )

Summary

Takes any number of arguments. Performs multiplication between the rightmost pair of elements, then the second-rightmost, et cetera. Multipies the value of the left element times value of right one. Note that references will modify the values of variables.
Returns a copy of the value the leftmost argument ended up with.

Multiplication rules

The table below contains rules for multiplying 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 Bool becomes FALSE. Equal to a logical AND. If number is non-zero, it's treated as TRUE. Bool multiplication is then performed. Float is treated as TRUE if absolute value of number is greater-or-equal to 1.0. Bool multiplication is then performed. String is treated as TRUE if it equals true or contains a non-zero number. Bool multiplication is then performed. Structure is treated as TRUE if it's non-empty. Bool multiplication is then performed.
bin Number becomes 0. Number is set to 0 if bool is FALSE. No type juggling needed. Multiplication is performed, the result truncated and then put into integer. String is converted to number (with regard to base). Multiplies by the number of entries in structure.
oct
int
hex
float Float becomes 0.0. Number is set to 0.0 if bool is FALSE. No type juggling needed. String is converted to float. Multiplies by number of entries in structure.
string Empty string. Empty string if bool is FALSE. If number is equal or lesser than zero, empty string. If number is 1, no effect. Otherwise, appends the string to itself appropriate number of times. Float is truncated, and then integer multiplication performed. No effect. Number of elements in structure is taken for a integer multiplication.
array Multiplication is performed on each structure element separately. Multiplication is performed between keys present in both structures.
dict

Example

# :mul example.
:set &NUM i20
:writeln $NUM
:mul &NUM s'20'
:writeln $NUM

wikistrona zmodyfikowana 2014/0601/2317