Defines | Functions

gcd.cc File Reference

#include "dNDArray.h"
#include "CNDArray.h"
#include "fNDArray.h"
#include "fCNDArray.h"
#include "lo-mappers.h"
#include "oct-binmap.h"
#include "defun-dld.h"
#include "error.h"
#include "oct-obj.h"
Include dependency graph for gcd.cc:

Go to the source code of this file.

Defines

#define MAKE_INT_BRANCH(X)
#define MAKE_INT_BRANCH(X)

Functions

 DEFUN_DLD (gcd, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{g} =} gcd (@var{a1}, @var{a2}, @dots{})\n\ @deftypefnx {Loadable Function} {[@var{g}, @var{v1}, @dots{}] =} gcd (@var{a1}, @var{a2}, @dots{})\n\ \n\ Compute the greatest common divisor of @var{a1}, @var{a2}, @dots{}. If more\n\ than one argument is given all arguments must be the same size or scalar.\n\ In this case the greatest common divisor is calculated for each element\n\ individually. All elements must be ordinary or Gaussian (complex)\n\ integers. Note that for Gaussian integers, the gcd is not unique up to\n\ units (multiplication by 1, -1, @var{i} or -@var{i}), so an arbitrary\n\ greatest common divisor amongst four possible is returned. For example,\n\ \n\ @noindent\n\ and\n\ \n\ @example\n\ @group\n\ gcd ([15, 9], [20, 18])\n\ @result{} 5 9\n\ @end group\n\ @end example\n\ \n\ Optional return arguments @var{v1}, etc., contain integer vectors such\n\ that,\n\ \n\ @tex\n\ $g = v_1 a_1 + v_2 a_2 + \\cdots$\n\ @end tex\n\ @ifnottex\n\ \n\ @example\n\ @var{g} = @var{v1} .* @var{a1} + @var{v2} .* @var{a2} + @dots{}\n\ @end example\n\ \n\ @end ifnottex\n\ \n\ @seealso{lcm, factor}\n\ @end deftypefn")
template<typename FP >
static void divide (const std::complex< FP > &a, const std::complex< FP > &b, std::complex< FP > &q, std::complex< FP > &r)
template<class NDA >
static octave_value do_extended_gcd (const octave_value &a, const octave_value &b, octave_value &x, octave_value &y)
template<class NDA >
static octave_value do_simple_gcd (const octave_value &a, const octave_value &b)
template<class T >
static octave_int< T > extended_gcd (const octave_int< T > &a, const octave_int< T > &b, octave_int< T > &x, octave_int< T > &y)
static double extended_gcd (double a, double b, double &x, double &y)
template<typename FP >
static std::complex< FP > extended_gcd (const std::complex< FP > &a, const std::complex< FP > &b, std::complex< FP > &x, std::complex< FP > &y)
template<class T >
static octave_int< T > simple_gcd (const octave_int< T > &a, const octave_int< T > &b)
static double simple_gcd (double a, double b)
template<typename FP >
static std::complex< FP > simple_gcd (const std::complex< FP > &a, const std::complex< FP > &b)

Define Documentation

#define MAKE_INT_BRANCH (   X  ) 
Value:
case btyp_ ## X: \
      retval = do_simple_gcd<X ## NDArray> (a, b); \
      break
#define MAKE_INT_BRANCH (   X  ) 
Value:
case btyp_ ## X: \
      retval = do_extended_gcd<X ## NDArray> (a, b, x, y); \
      break

Function Documentation

DEFUN_DLD ( gcd  ,
args  ,
nargout   
)
template<typename FP >
static void divide ( const std::complex< FP > &  a,
const std::complex< FP > &  b,
std::complex< FP > &  q,
std::complex< FP > &  r 
) [static]

Definition at line 64 of file gcd.cc.

References floor(), imag(), and real.

Referenced by extended_gcd(), and simple_gcd().

template<class NDA >
static octave_value do_extended_gcd ( const octave_value a,
const octave_value b,
octave_value x,
octave_value y 
) [static]
template<class NDA >
static octave_value do_simple_gcd ( const octave_value a,
const octave_value b 
) [static]
template<class T >
static octave_int<T> extended_gcd ( const octave_int< T > &  a,
const octave_int< T > &  b,
octave_int< T > &  x,
octave_int< T > &  y 
) [static]

Definition at line 202 of file gcd.cc.

References octave_int< T >::value().

static double extended_gcd ( double  a,
double  b,
double x,
double y 
) [static]

Definition at line 119 of file gcd.cc.

References floor(), and xisinteger().

template<typename FP >
static std::complex<FP> extended_gcd ( const std::complex< FP > &  a,
const std::complex< FP > &  b,
std::complex< FP > &  x,
std::complex< FP > &  y 
) [static]

Definition at line 156 of file gcd.cc.

References abs(), divide(), and xisinteger().

template<class T >
static octave_int<T> simple_gcd ( const octave_int< T > &  a,
const octave_int< T > &  b 
) [static]

Definition at line 103 of file gcd.cc.

References octave_int< T >::value().

static double simple_gcd ( double  a,
double  b 
) [static]

Definition at line 40 of file gcd.cc.

References xisinteger().

template<typename FP >
static std::complex<FP> simple_gcd ( const std::complex< FP > &  a,
const std::complex< FP > &  b 
) [static]

Definition at line 77 of file gcd.cc.

References abs(), divide(), and xisinteger().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines