Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public boolean isCommutative() {
* For example, for base = 2, this does bit decomposition.
*
* @return an array {@code A} containing values {@code A[i] < base} such that
* \(\sum_i{ \text{A}[i] \cdot \text{base}^i} = \text{number}\)
* \(\sum_i{ \text{A}[i] \cdot \text{base}^i} = \text{number}\)
*/
public static BigInteger[] decomposeIntoDigits(BigInteger number, BigInteger base) {
int power = 0;
BigInteger numberPowered = BigInteger.ONE;
// as soon as number is smaller than number^power, it can be decomposed into power digits.
while (numberPowered.compareTo(number) < 0) {
numberPowered = numberPowered.multiply(number);
BigInteger basePower = BigInteger.ONE;
// as soon as number is smaller than base^power, it can be decomposed into power digits.
while (basePower.compareTo(number) < 0) {
basePower = basePower.multiply(base);
power++;
}
return decomposeIntoDigits(number, base, power);
Expand All @@ -116,7 +116,7 @@ public static BigInteger[] decomposeIntoDigits(BigInteger number, BigInteger bas
* For example, for base = 2, this does bit decomposition.
*
* @return an array {@code A} containing values {@code A[i] < base} such that
* \(\sum_i{ \text{A}[i] \cdot \text{base}^i} = \text{number}\)
* \(\sum_i{ \text{A}[i] \cdot \text{base}^i} = \text{number}\)
* @throws IllegalArgumentException if {@code numDigits} is not enough to represent the given number
*/
public static BigInteger[] decomposeIntoDigits(BigInteger number, BigInteger base, int numDigits) {
Expand Down