div¶
Syntax¶
Parameters¶
x- An expression that evaluates to a number or a list.
y- An expression that evaluates to a number or a list.
Returns¶
The result is a single value if both arguments are single-valued expressions; otherwise the result is a list.
Description¶
If x and y are single-valued expressions, the action returns the quotient
of x, the dividend, and y, the divisor (i.e. x / y).
When x is a single-valued expression and y is a list, the operation
produces a list of quotients by dividing x by each element in y, treating
the single value as the dividend and each list element as a separate divisor.
When x is a list and y is a single-valued expression, the operation
produces a list of quotients by dividing each element in x by y, treating
each list element as a separate dividend and the single value as the divisor.
If both arguments are list-expressions, then the action returns a list of the
quotients by dividing each element in x by the value at the corresponding
index in y. In this case, the lists must have the same number of elements.
This action is the prefix notation for the expression x / y.
If both arguments are list-expressions, a run-time error occurs if the lists have different lengths. A run-time error occurs If the divisor is zero.
Examples¶
z = div(12, 4) # z = 3
z = 12 / 4 # z = 3
a_list = list(10, 20, 40)
new_list = div(a_list, 10) # new_list = list(1, 2, 4)
new_list = a_list / 10 # new_list = list(1, 2, 4)
new_list = 10 / a_list # new_list = list(1, 0.5, 0.25)
a_list = list(10, 20, 40)
b_list = list(2, 5, 8)
new_list = a_list / b_list # new_list = list(5, 4, 5)