The numerical functions shown in table 8.22 work on different data types.
| Operation | Meaning | HALCON operator |
| min(t) | minimum value of the tuple | tuple_min |
| min2(t1,t2) | elementwise minimum of two tuples | tuple_min2 |
| max(t) | maximum value of the tuple | tuple_max |
| max2(t1,t2) | elementwise maximum of two tuples | tuple_max2 |
| sum(t) | sum of all tuple elements or string concatenation | tuple_sum |
| mean(a) | mean value | tuple_mean |
| deviation(a) | standard deviation | tuple_deviation |
| cumul(a) | cumulative sums of a tuple | tuple_cumul |
| median(a) | median of a tuple | tuple_median |
| select_rank(a,i) | element at rank i of a tuple | tuple_select_rank |
| sqrt(a) | square root √(a) | tuple_sqrt |
| cbrt(a) | cube root ∛(a); | tuple_cbrt |
| hypot(a,b) | hypotenuse √(a2 + b2) | tuple_hypot |
| deg(a) | convert radians to degrees | tuple_deg |
| rad(a) | convert degrees to radians | tuple_rad |
| real(a) | convert integer to real | tuple_real |
| int(a) | truncate real to integer | tuple_int |
| round(a) | convert real to integer | tuple_round |
| abs(a) | absolute value of a (integer or real) | tuple_abs |
| fabs(a) | absolute value of a (always real) | tuple_fabs |
| ceil(a) | smallest integer value not smaller than a | tuple_ceil |
| floor(a) | largest integer value not greater than a | tuple_floor |
| fmod(a1,a2) | fractional part of a1/a2, with the same sign as a1 | tuple_fmod |
| sgn(a) | elementwise sign of a tuple | tuple_sgn |
Table 8.22: Numerical functions.
The functions min and max select the minimum and the maximum values of the tuple values. All of these values either have to be of type string, or integer/real. It is not allowed to mix strings with numerical values. The resulting value will be of type real, if at least one of the elements is of type real. If all elements are of type integer the resulting value will also be of type integer. The same applies to the function sum that determines the sum of all values. If the input arguments are strings, string concatenation will be used instead of addition.
The functions mean, deviation, sqrt, cbrt, deg, rad, fabs, ceil, floor and fmod work with integer and real; the result is always of type real. The function mean calculates the mean value and deviation the standard deviation of numbers. sqrt calculates the square root of a number. cbrt calculates the cube root of a number. hypot calculates the hypotenuse of two numbers.
cumul returns the different cumulative sums of the corresponding elements of the input tuple, and median calculates the median of a tuple. For both functions, the resulting value will be of type real, if at least one of the elements is of type real. If all elements are of type integer the resulting value will also be of type integer. select_rank returns the element at rank i and works for tuples containing int or real values. The index i is of type int.
deg and rad convert numbers from radians to degrees and from degrees to radians, respectively.
real converts an integer to a real. For real as input it returns the input. int converts a real to an integer and truncates it. round converts a real to an integer and rounds the value. For integer it returns the input. The function abs always returns the absolute value that is of the same type as the input value.
The following example (file name: euclid_distance.hdev) shows the use of some numerical functions:
V1 := [18.8,132.4,33,19.3] V2 := [233.23,32.786,234.4224,63.33] Diff := V1 - V2 Distance := sqrt(sum(Diff * Diff)) Dotvalue := sum(V1 * V2)
First, the Euclidian distance of the two vectors V1 and V2 is computed, by using the formula:
d = √(∑i(V1i − V2i)2)
The difference and the multiplication (square) are successively applied to each element of both vectors. Afterwards sum computes the sum of the squares. Then the square root of the sum is calculated. After that the dot product of V1 and V2 is determined by the formula:
<V1, V2> = ∑i(V1i * V2i)