View Raw SPL
/*****************************************************************************
*                                                                            *
*   VMIN.SPL   Copyright (C) 2001 DSP Development Corporation                *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Returns minimum of one or more input arguments              *
*                                                                            *
*   Revisions:    9 Aug 2001  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/


#if @HELP_VMIN

    VMIN

    Purpose: Returns the minimum of one or more input arguments

    Syntax:  VMIN(val1, val2, ..., valN)

                 val1  -  1st series or numeric argument
                 val2  -  2nd series or numeric argument
                 valN  -  Nth series or numeric argument

    Returns: A real or series

    Example:
             vmin(10, 15, 20)

             returns 10

             vmin({1, 2, 3}, {0, 4, 2}, {0, 3, 8})

             returns the series {0, 2, 2}

    Example:
             W1:{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
             W2: vmin(w1)

             W2 == {1, 2, 3} the minimums of each column of W1.

    Remarks:
             VMIN with no input arguments uses the current Window. VMIN
             is an SPL routine that accepts a variable number of input
             arguments.

    See Also:
             Max
             Maxval
             Min
             Minval
             Vmax

#endif


/* minimum of one or more inputs */
vmin(argv)
{
        local i, s;

        /* 0 or 1 arg case */
        if (argc < 2)
        {
                if (argc < 1)
                {
                        s = minval();
                }
                else
                {
                        s = minval(getargv(1));
                }
        }
        else
        {
                /* initialize */
                s = minval(getargv(1), getargv(2));

                /* compare input args */
                loop (i = 3..argc)
                {
                        s = minval(s, getargv(i));
                }
        }
        
        return(s);
}