div()
Returns the quotient of dividend and a divisor parameters.
Synopsis
div(x, y)
Description
If x
and y
are single-valued expressions, the function returns
the quotient of x, the dividend, and y, the divisor: x / y
.
If the first argument is a single-valued expression and the second is a list-expression, the function returns a list of quotients where the divisor is the first parameter and each value in the list is treated as a dividend.
If the first argument is a list-expression and the second is a single-valued expression, the function returns a list of quotients where each value in the list is treated as a divisor, and the second parameter is the dividend.
If both arguments are list-expressions, then the function returns a list of the quotients of the items in the first list divided by value at each corresponding index in the second list. In this case, the lists must have the same number of items.
This function is the prefix notation for the expression x / y
.
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.
Errors
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)