math/div

Usage

Description

Input

Output

Examples

Divide two scalars

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)

Divide a row vector by a matrix (broadcast by rows)

Complex division

Details

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

X1

int, uint, float, rational, complex, [T], [[T]]

Dividend. Supports element-wise division for scalars, vectors, and matrices.

X2

int, uint, float, rational, complex, [T], [[T]]

Divisor. Must be shape-compatible with X1 under the broadcasting rules.

Supported scalar types: i8, i16, i32, i64, i128, u8, u16, u32, u64, u128, f32, f64, rational (R64), and complex (C64).

Output

Argument

Kind

Description

Y

matches input

Element-wise quotient of X1 / X2. The shape of Y follows broadcasting.

Examples

Divide two scalars

y:=math/div(10, 2)--

5

Divide two vectors

x1:=[
10
20
30
]
x2:=[
2
4
5
]

Divide two matrices

a:=[
10 30
20 40
]
b:=[
2 5
4 10
]

Divide a matrix by a scalar

a:=[
10 30
20 40
]

Divide a scalar by a matrix

m:=[
1 4
2 5
]

Divide a matrix by a column vector (broadcast by columns)

m:=[
10 30
20 40
]
--

2x2

v:=[
2
5
]
--

column vector length 2

Divide a row vector by a matrix (broadcast by rows)

r:=[
100
200
]
m:=[
2 5
4 10
]

Complex division

y:=math/div(1+2i, 3+-4i)

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-m vector can divide an m×n matrix column-wise.

  • Matrix ÷ Row Vector (or Row Vector ÷ Matrix): A length-n vector can divide an m×n matrix 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.