private void TestToBigInteger() { Random rng = new Random(); byte[] a = new byte[1 + rng.Next(100)]; rng.NextBytes(a); int[] b = SchonhageStrassen.ToIntArray(new BigInteger(1, a)); BigInteger c = SchonhageStrassen.ToBigInteger(b); if (!Compare.Equals(new BigInteger(1, a), c)) { throw new Exception("SchönhageStrassen:ToBigInteger test has failed!"); } }
private int[] ToIntArray(BigIntPolynomial A, int K) { int N = A.Coeffs.Length; int sign = A.Coeffs[A.Degree()].Signum(); int[] aInt = new int[N * K]; for (int i = N - 1; i >= 0; i--) { int[] cArr = SchonhageStrassen.ToIntArray(A.Coeffs[i].Abs()); if (A.Coeffs[i].Signum() * sign < 0) { SubShifted(aInt, cArr, i * K); } else { AddShifted(aInt, cArr, i * K); } } return(aInt); }