Native functions standard library

# Native functions standard library

Aseba provides a standard library of native functions. Targets should normally1 provide this library. If your target's firmware holds an old version of Aseba, not all functions may be available. In Aseba version 1.1, the following functions are available:2

math.copy(A,B)
Copy the array $B$ in the array $A$, element by element: $A_i = B_i$.
math.fill(A,c)
Fill each element of the array $A$ with the constant $c$: $A_i = c$.
math.addscalar(A, B, c)
Compute $A_i = B_i + c$ where $c$ is a scalar.
math.add(A, B, C)
Compute $A_i = B_i + C_i$ where $A$, $B$ and $C$ are three arrays of the same size.
math.sub(A, B, C)
Compute $A_i = B_i - C_i$ where $A$, $B$ and $C$ are three arrays of the same size.
math.mul(A, B, C)
Compute $A_i = B_i \cdot C_i$ where $A$, $B$ and $C$ are three arrays of the same size. Note that this is not a dot product.
math.div(A, B, C)
Compute $A_i = B_i / C_i$ where $A$, $B$ and $C$ are three arrays of the same size. An exception will be triggered if a division by zero occurs.
math.min(A, B, C)
Write the minimum of each element of $B$ and $C$ in $A$ where $A$, $B$ and $C$ are three arrays of the same size: $A_i = \mathrm{min}(B_i, C_i)$.
math.max(A, B, C)
Write the maximum of each element of $B$ and $C$ in $A$ where $A$, $B$ and $C$ are three arrays of the same size: $A_i = \mathrm{max}(B_i, C_i)$.
math.clamp(A,B,C,D)
Clamp each element $B_i$ that $C_i<A_i<D_i$ and store it in $A_i$.
math.dot(r, A, B, n)
Compute the dot product between two arrays of the same size $A$ and $B$: $r = \frac{\sum_i(A_i\cdot B_i)}{2^{n}}$
math.stat(V, min, max, mean)
Compute the minimum, the maximum and the mean values of array $V$.
math.argbounds(A, argmin, argmax)
Get the indices argmin and argmax corresponding to the minimum respectively maximum values of array $A$.
math.sort(A)
Sort the array $A$ in place.
math.muldiv(A, B, C, D)
Compute multiplication-division using internal 32-bit precision: $A_i = \frac{B_i\cdot C_i}{D_i}$. An exception will be triggered if a division by zero occurs.
math.atan2(A, Y, X)
Compute $A_i=\arctan\left(\frac{Y_i}{X_i}\right)$ using the signs of $Y_i$ and $X_i$ to determine the quadrant of the output, where $A$, $Y$ and $X$ are three arrays of the same size. Note that $X_i = 0$ and $Y_i = 0$ will produce $A_i = 0$..
math.sin(A, B)
Compute $A_i = \sin(B_i)$ where $A$ and $B$ are two arrays of the same size.
math.cos(A, B)
Compute $A_i = \cos(B_i)$ where $A$ and $B$ are two arrays of the same size.
math.rot2(A, B, angle)
Rotate the array $B$ by angle, write the result to $A$. Note that $A$ and $B$ must both be arrays of size 2.
math.sqrt(A, B)
Compute $A_i = \sqrt{B_i}$ where $A$ and $B$ are two arrays of the same size.
math.rand(v)
Return a random value $v$ in the range $-32768:32767$.

Since a scalar is considered to be an array of size one, you can use these functions on scalars:

var theta = 16384
var cos_theta
call math.cos(cos_theta, theta)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License