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);
65 safepower (uint64_t a, uint64_t b, uint64_t modulus)
84 if (
x == 1 ||
x ==
n-1)
87 for (uint64_t j = 1; j <
r; j++)
148 DEFUN (__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)
251 DEFUN (__pollardrho__, args, ,
262 if (args.length () != 1)
266 (
"__pollardrho__: unable to convert input. Call factor() instead.");
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)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error_unless(bool cond)
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.