code wiki / (root) / nx_dot_product_test.nx

nx_dot_product_test.nx source

↩ module page · 32 lines · 1024 B

1import "nx_syscalls.nx" 2import "nx_dot_product.nx" 3 4func main() -> nx_int { 5 let buf_a: *u8 = sys_mmap(80) 6 let buf_b: *u8 = sys_mmap(80) 7 let a: *nx_int = buf_a as *nx_int 8 let b: *nx_int = buf_b as *nx_int 9 10 a[0] = 1; a[1] = 2; a[2] = 3 11 b[0] = 4; b[1] = 5; b[2] = 6 12 // 1*4 + 2*5 + 3*6 = 4 + 10 + 18 = 32 13 if nx_dot_product(a, b, 3) != 32 { return __syscall(93, 1, 0, 0, 0, 0, 0) } 14 15 // empty vectors 16 if nx_dot_product(a, b, 0) != 0 { return __syscall(93, 2, 0, 0, 0, 0, 0) } 17 18 // orthogonal vectors (perpendicular) 19 a[0] = 1; a[1] = 0 20 b[0] = 0; b[1] = 1 21 if nx_dot_product(a, b, 2) != 0 { return __syscall(93, 3, 0, 0, 0, 0, 0) } 22 23 // self-dot = length^2 24 a[0] = 3; a[1] = 4 25 if nx_dot_product(a, a, 2) != 25 { return __syscall(93, 4, 0, 0, 0, 0, 0) } 26 27 // negatives 28 a[0] = -1; a[1] = -2; a[2] = -3 29 b[0] = 1; b[1] = 2; b[2] = 3 30 if nx_dot_product(a, b, 3) != -14 { return __syscall(93, 5, 0, 0, 0, 0, 0) } 31 return 0 32}