simdDiv
simdDiv divides corresponding elements and returns a new array in Result<T[], SimdError>.
simdDiv<T>(left: T[], right: T[]): Result<T[], SimdError>import { simdDiv, SimdError } from "tyrus:simd";
const left: i32[] = [100, 81, 72, 55, 42];
const right: i32[] = [10, 9, 8, 5, 6];
const result: Result<i32[], SimdError> = simdDiv(left, right);
match (result) {
Ok(values) => {
print(values); // [10, 9, 9, 11, 7]
}
Err(error) => {
printError(error.code, error.message);
}
}Floating-point division follows IEEE behavior. Dividing nonzero values by 0.0 produces infinity, and 0.0 / 0.0 produces NaN; these results are returned in Ok.
Integer division truncates toward zero. A zero divisor in any integer lane returns ERR_SIMD_DIVISION_BY_ZERO. Signed minimum divided by -1 returns ERR_SIMD_INTEGER_OVERFLOW because the exact quotient is outside the lane type. The operation checks every integer lane before division, so an invalid lane never reaches an integer divide. Floating-point division follows IEEE behavior and returns infinities or NaN in Ok when appropriate. Dynamic length mismatch and result allocation failure also return SimdError. Fixed-size arrays can be passed directly; unequal fixed lengths are rejected with E0308 at compile time. Supported element types are i8, i16, i32, i64, u8, u16, u32, u64, f32, and f64.
Floating-point division by zero
Floating-point division by zero follows IEEE 754 and returns these values in Ok: 1.0 / 0.0 produces Infinity, -1.0 / 0.0 produces -Infinity, and 0.0 / 0.0 produces NaN.
import { simdDiv, SimdError } from "tyrus:simd";
const main = (): void => {
const numerators: f32[] = [1.0, -1.0, 0.0];
const denominators: f32[] = [0.0; 3];
const result: Result<f32[], SimdError> = simdDiv(numerators, denominators);
match (result) {
Ok(values) => {
print(values); // [Infinity, -Infinity, NaN]
}
Err(error) => {
printError(error.code, error.message);
}
}
};Errors
error
A zero integer divisor returns a recoverable error:
import { simdDiv, SimdError } from "tyrus:simd";
const left: i32[] = [100, 81, 72, 55];
const right: i32[] = [10, 0, 8, 5];
const result: Result<i32[], SimdError> = simdDiv(left, right);
match (result) {
Ok(values) => { print(values); }
Err(error) => { printError(error.code, error.message); }
}ERR_SIMD_DIVISION_BY_ZERO simdDiv cannot divide an integer lane by zeroerror
Signed minimum divided by -1 also returns a recoverable error:
import { simdDiv, SimdError } from "tyrus:simd";
const left: i8[] = [-128; 1];
const right: i8[] = [-1; 1];
const result: Result<i8[], SimdError> = simdDiv(left, right);
match (result) {
Ok(values) => { print(values); }
Err(error) => { printError(error.code, error.message); }
}ERR_SIMD_INTEGER_OVERFLOW simdDiv cannot represent the signed minimum divided by -1