math/div
Element-wise division
Usage
Y:=math/div(X1, X2)Description
Performs element-wise division of two numeric inputs. X1 is divided by X2. Inputs may be scalars, vectors, or matrices. When one input is a scalar and the other is an array, the scalar is broadcast across the array. For vector-matrix and row/column operations, broadcasting follows the rules described in Details.
Input
Argument | Kind | Description |
|---|---|---|
|
| Dividend. Supports element-wise division for scalars, vectors, and matrices. |
|
| Divisor. Must be shape-compatible with |
Supported scalar types: i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64, rational (R64), and complex (C64).
Output
Argument | Kind | Description |
|---|---|---|
| matches input | Element-wise quotient of |
Examples
Divide two scalars
5
Divide two vectors
Divide two matrices
Divide a matrix by a scalar
Divide a scalar by a matrix
Divide a matrix by a column vector (broadcast by columns)
2x2
v:=[column vector length 2
Divide a row vector by a matrix (broadcast by rows)
Complex division
Details
Element-wise semantics. Division is performed element by element. Shapes must either match or be compatible under broadcasting.
Broadcasting rules.
Scalar ÷ Array or Array ÷ Scalar: The scalar is broadcast across every element of the array.
Matrix ÷ Column Vector (or Vector ÷ Matrix): A length-
mvector can divide anm×nmatrix column-wise.Matrix ÷ Row Vector (or Row Vector ÷ Matrix): A length-
nvector can divide anm×nmatrix row-wise.
Division by zero. If an element of the divisor is zero, the result may be Inf, NaN, or raise an error depending on type and runtime.
Type support. Implemented for signed/unsigned integers, floating-point, rationals, and complex numbers. Standard type promotions apply where supported.
Errors.
Shape mismatch that cannot be resolved by broadcasting.
Division by zero in integer or rational contexts.
Unsupported type combination.