Question :
I’m trying to use the GCD
library function BigINT.js . But I do not know how, I try to use raw numbers, but it returns 0
In the description says
// bigInt GCD(x,y)
// return greatest common divisor of bigInts x and y (each with same number of elements).
And I try to use it like this:
GCD(1124,2048);
But it turns 0. How to use it correctly?
Answer :
From the library code, in the same link you passed, you can see that the GCD
function expects you to pass two numbers in the bigInt
format, rather than numeric JavaScript types.
To convert numeric JavaScript types to bigInt
, there is the int2bigInt
function.
-
You can read the following documentation at the top of the file:
// bigInt int2bigInt (t, n, m) // return a bigInt equal to integer t, with at least n bits and m array elements
translating:
// bigInt int2bigInt (t, n, m) // returns a bigInt equal to integer t, with at least n bits and an array of m elements
After obtaining the MDC, you can convert bigInt
to string and display its value, using the bigInt2str
function:
-
still in the documentation at the top of the file:
// string bigInt2str (x, base) // return a string form of bigInt x in a given base, with 2