View Raw SPL
/*****************************************************************************
*                                                                            *
*   COMPLEX.SPL  Copyright (C) 2010 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Create a complex number or series                           *
*                                                                            *
*   Revisions:   30 Jul 2010  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/

#include 


#if @HELP_COMPLEX

    COMPLEX

    Purpose: Combines two input expressions into complex Cartesian 
             (Real/Imaginary) form.

    Syntax:  COMPLEX(expr1, expr2)

             expr1 - Any expression evaluating to a scalar, series, or table.

             expr2 - Any expression evaluating to a scalar, series, or table.

   Returns:
             Complex scalar, series, or table in Real/Imaginary form.

   Example:
             complex(1, 2)

             returns the scalar 1 + 2i.

   Example:
             complex(1)

             returns the scalar 1 + 0i.

   Example:
             complex(1..5, 2)

             returns the complex series {1+2i, 2+2i, 3+2i, 4+2i, 5+2i}.

   Example:
             complex(W1, W2)

             is equivalent to W1 + W2*i for W1 and W2 real series.

   Remarks:
             Returns a Complex value regardless of the input value.  If
             at least one of the input arguments is a series, COMPLEX
             returns a Complex series.

             complex(a, b) is equivalent to a + b*i.

             For complex inputs, complex(a, b) is equivalent to: 

             real(a) + real(b)*i.

  See Also:
             CARTESIAN 
             IMAGINARY
             MAKECARTESIAN
             MAKEPOLAR
             PHASE 
             POLAR
             REAL
#endif



/* make a complex number */
complex(a, b)
{
        if (argc < 2)
        {
                if (argc < 1) error("complex - input value required");
                
                b = 0;
        }
        
        /* a + bi */
        return(makecartesian(a, b));
}