isden

Purpose

Returns whether a scalar, matrix or N-dimensional array contains denormals.

Format

x_isden = isden(x)
Parameters:x (NxK matrix or N-dimensional array) – data
Returns:x_isden (scalar) – 1 if x contains a denormal, 0 if it does not.

Examples

Sometimes denormals can unnecessarily slow down calculations and it is best to flush them to zero. This example tests whether the vector x contains any denormals and then sets any values between 0 and 1e-25 to be equal to 0.

tol = 1e-25;

// Create a vector that contains a denormal
x = { 1, exp(-724.5), 3 };

if isden(x);
   // Get the index of all elements between 0 and tol
   idx = indexcat(x, 0|tol);

   // Set all elements between 0 and tol equal to 0
   x[idx] = 0;

endif;

Before the if, else, elseif, endif block in the code above, the second element of x is equal to approximately 3e-57. After the if, else, elseif, endif block this element is set equal to 0, the other elements of x are unchanged.

This results in :

    1.0000000000
x = 0.0000000000
    3.0000000000

See also

Functions denToZero()