simdSub
simdSub subtracts corresponding elements in the right array from the left array and returns a new array inside Result<T[], SimdError>.
Signature
simdSub<T>(left: T[], right: T[]): Result<T[], SimdError>tyrus
import { simdSub, SimdError } from "tyrus:simd";
const left: i32[] = [20, 30, 40, 50, 60];
const right: i32[] = [3, 4, 5, 6, 7];
const result: Result<i32[], SimdError> = simdSub(left, right);
match (result) {
Ok(values) => {
print(values); // [17, 26, 35, 44, 53]
}
Err(error) => {
printError(error.code, error.message);
}
}The supported element types are i8, i16, i32, i64, u8, u16, u32, u64, f32, and f64. Signed and unsigned integer subtraction wraps by default at the element width; for example, subtracting 1 from 0 as u8 produces 255. Integer literals must still fit their declared element type at compile time. Dynamic input length mismatch and result allocation failure return SimdError values. Different fixed input lengths are rejected with E0308 at compile time.
Errors
error
tyrus
import { simdSub, SimdError } from "tyrus:simd";
const left: i32[] = [1, 2];
const right: i32[] = [3, 4, 5];
const result: Result<i32[], SimdError> = simdSub(left, right);
match (result) {
Ok(_) => {}
Err(error) => { printError(error.code, error.message); }
}text
ERR_SIMD_LENGTH_MISMATCH simdSub requires arrays of equal lengtherror
tyrus
import { simdSub } from "tyrus:simd";
const left: i32[] = [1, 2];
const right: i64[] = [3, 4];
const result = simdSub(left, right); text
error[E0308]: type mismatch for argument 2 of `simdSub`: expected `i32[]`, found `i64[]`
at /src/main.tyr:5:16
const result = simdSub(left, right);
^^^^^^^