Skip to content

BigInt#divRem using O(n²) algorithm? #9

@janvanoort

Description

@janvanoort

The divRem( final BigInt div) operation is essentially the arithmetic modulo operation. Two suggestions:

  1. rename the method to modulo, for more clarity
  2. implement the much simpler subtraction-based Euclidean algorithm, as in

function gcd(a, b)
while a ≠ b
if a > b
a := a − b;
else
b := b − a;
return a;

(See image for Euclid's original source, formulated geometrically as Euclid was wont to do.)
If 2. is decided upon, I am willing to provide an implementation plus a unit test for the implementation plus a perf test comparing it side-by-side to the existing implementation.

img_20190125_105113_hdr

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions