26#if defined (HAVE_CONFIG_H)
55 uint64_t q = modulus / a;
56 uint64_t r = modulus - q * a;
57 uint64_t term1 = a * (b % q);
58 uint64_t term2 = (r < q) ? r * (b / q) :
safemultiply (r, b / q, modulus);
59 return (term1 > term2) ? (term1 - term2) : (term1 + modulus - term2);
84 if (
x == 1 ||
x == n-1)
87 for (uint64_t j = 1; j < r; j++)
148DEFUN (__isprimelarge__, args, ,
158 if (args.length () != 1)
165 (
"__isprimelarge__: unable to convert input. Call isprime() instead.");
207 return (a <= b) ? ( (b % a == 0) ? a :
localgcd (a, b % a) )
208 : ( (a % b == 0) ? b :
localgcd (a % b, b) );
217 uint64_t i = 1, j = 2;
218 uint64_t
x = (c+1) % n;
240 if (g == n || i > 1000000)
248DEFUN (__pollardrho__, args, ,
259 if (args.length () != 1)
263 (
"__pollardrho__: unable to convert input. Call factor() instead.");
278OCTAVE_END_NAMESPACE(octave)
bool isprimescalar(uint64_t n)
bool millerrabin(uint64_t div, uint64_t d, uint64_t r, uint64_t n)
uint64_t safemultiply(uint64_t a, uint64_t b, uint64_t modulus)
uint64_t localgcd(uint64_t a, uint64_t b)
uint64_t pollardrho(uint64_t n, uint64_t c=1)
uint64_t safepower(uint64_t a, uint64_t b, uint64_t modulus)
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
octave_idx_type numel() const
Number of elements in the array.
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
F77_RET_T const F77_DBLE * x
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.