vec_sel

Purpose

Returns a vector containing the value of either a or b depending on the value of c.

Syntax

d=vec_sel(a, b, c)

Result and argument types

The following table describes the types of the returned value and the function arguments.

d a b c
vector4double vector4double vector4double vector4double

Result value

The value of each element of the result is equal to the corresponding element of b if the corresponding element of c is greater than or equal to zero (regardless of sign), or the value is equal to the corresponding element of a if the corresponding element of c is less than zero or NaN.

Formula

If (c[0] ≥ 0) Then d[0] = b[0] Else d[0] = a[0]
If (c[1] ≥ 0) Then d[1] = b[1] Else d[1] = a[1]
If (c[2] ≥ 0) Then d[2] = b[2] Else d[2] = a[2]
If (c[3] ≥ 0) Then d[3] = b[3] Else d[3] = a[3]

Example

a =  (20.0,  20.0, 20.0,  20.0)
b =  (10.0,  10.0, 10.0,  10.0)
c =  ( 1.0,  -1.0,  2.5,  -2.5)
d: (10.0,  20.0, 10.0,  20.0)