#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"
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 MAKE_INT_BRANCH | ( | X | ) |
case btyp_ ## X: \ retval = do_simple_gcd<X ## NDArray> (a, b); \ break
#define MAKE_INT_BRANCH | ( | X | ) |
case btyp_ ## X: \ retval = do_extended_gcd<X ## NDArray> (a, b, x, y); \ break
DEFUN_DLD | ( | gcd | , | |
args | , | |||
nargout | ||||
) |
Definition at line 435 of file gcd.cc.
References do_extended_gcd(), do_simple_gcd(), error_state, octave_value::length(), octave_value::op_el_mul_eq, print_usage(), and octave_value_list::resize().
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().
static octave_value do_extended_gcd | ( | const octave_value & | a, | |
const octave_value & | b, | |||
octave_value & | x, | |||
octave_value & | y | |||
) | [static] |
Definition at line 374 of file gcd.cc.
References btyp_complex, btyp_double, btyp_float, btyp_float_complex, btyp_mixed_numeric(), octave_value::builtin_type(), error(), error_state, octave_value::float_array_value(), octave_value::is_sparse_type(), MAKE_INT_BRANCH, and octave_value::sparse_matrix_value().
Referenced by DEFUN_DLD().
static octave_value do_simple_gcd | ( | const octave_value & | a, | |
const octave_value & | b | |||
) | [static] |
Definition at line 258 of file gcd.cc.
References btyp_complex, btyp_double, btyp_float, btyp_float_complex, btyp_mixed_numeric(), octave_value::builtin_type(), octave_value::class_name(), error(), octave_value::float_array_value(), octave_value::is_sparse_type(), and MAKE_INT_BRANCH.
Referenced by DEFUN_DLD().
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().
Definition at line 119 of file gcd.cc.
References floor(), and xisinteger().
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().
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().
Definition at line 40 of file gcd.cc.
References xisinteger().
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().