1361 lines
30 KiB
Smali
1361 lines
30 KiB
Smali
.class public final Lcom/google/common/math/BigIntegerMath;
|
|
.super Ljava/lang/Object;
|
|
.source "BigIntegerMath.java"
|
|
|
|
|
|
# annotations
|
|
.annotation build Lcom/google/common/annotations/GwtCompatible;
|
|
emulated = true
|
|
.end annotation
|
|
|
|
.annotation runtime Lcom/google/common/math/ElementTypesAreNonnullByDefault;
|
|
.end annotation
|
|
|
|
.annotation system Ldalvik/annotation/MemberClasses;
|
|
value = {
|
|
Lcom/google/common/math/BigIntegerMath$BigIntegerToDoubleRounder;
|
|
}
|
|
.end annotation
|
|
|
|
|
|
# static fields
|
|
.field private static final LN_10:D
|
|
|
|
.field private static final LN_2:D
|
|
|
|
.field public static final SQRT2_PRECOMPUTED_BITS:Ljava/math/BigInteger;
|
|
.annotation build Lcom/google/common/annotations/VisibleForTesting;
|
|
.end annotation
|
|
.end field
|
|
|
|
.field public static final SQRT2_PRECOMPUTE_THRESHOLD:I = 0x100
|
|
.annotation build Lcom/google/common/annotations/VisibleForTesting;
|
|
.end annotation
|
|
.end field
|
|
|
|
|
|
# direct methods
|
|
.method public static constructor <clinit>()V
|
|
.locals 3
|
|
|
|
.line 1
|
|
new-instance v0, Ljava/math/BigInteger;
|
|
|
|
const-string v1, "16a09e667f3bcc908b2fb1366ea957d3e3adec17512775099da2f590b0667322a"
|
|
|
|
const/16 v2, 0x10
|
|
|
|
invoke-direct {v0, v1, v2}, Ljava/math/BigInteger;-><init>(Ljava/lang/String;I)V
|
|
|
|
sput-object v0, Lcom/google/common/math/BigIntegerMath;->SQRT2_PRECOMPUTED_BITS:Ljava/math/BigInteger;
|
|
|
|
const-wide/high16 v0, 0x4024000000000000L # 10.0
|
|
|
|
.line 2
|
|
invoke-static {v0, v1}, Ljava/lang/Math;->log(D)D
|
|
|
|
move-result-wide v0
|
|
|
|
sput-wide v0, Lcom/google/common/math/BigIntegerMath;->LN_10:D
|
|
|
|
const-wide/high16 v0, 0x4000000000000000L # 2.0
|
|
|
|
.line 3
|
|
invoke-static {v0, v1}, Ljava/lang/Math;->log(D)D
|
|
|
|
move-result-wide v0
|
|
|
|
sput-wide v0, Lcom/google/common/math/BigIntegerMath;->LN_2:D
|
|
|
|
return-void
|
|
.end method
|
|
|
|
.method private constructor <init>()V
|
|
.locals 0
|
|
|
|
.line 1
|
|
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
|
|
|
|
return-void
|
|
.end method
|
|
|
|
.method public static binomial(II)Ljava/math/BigInteger;
|
|
.locals 10
|
|
|
|
const-string v0, "n"
|
|
|
|
.line 1
|
|
invoke-static {v0, p0}, Lcom/google/common/math/MathPreconditions;->checkNonNegative(Ljava/lang/String;I)I
|
|
|
|
const-string v0, "k"
|
|
|
|
.line 2
|
|
invoke-static {v0, p1}, Lcom/google/common/math/MathPreconditions;->checkNonNegative(Ljava/lang/String;I)I
|
|
|
|
const/4 v0, 0x1
|
|
|
|
if-gt p1, p0, :cond_0
|
|
|
|
move v1, v0
|
|
|
|
goto :goto_0
|
|
|
|
:cond_0
|
|
const/4 v1, 0x0
|
|
|
|
:goto_0
|
|
const-string v2, "k (%s) > n (%s)"
|
|
|
|
.line 3
|
|
invoke-static {v1, v2, p1, p0}, Lcom/google/common/base/Preconditions;->checkArgument(ZLjava/lang/String;II)V
|
|
|
|
shr-int/lit8 v1, p0, 0x1
|
|
|
|
if-le p1, v1, :cond_1
|
|
|
|
sub-int p1, p0, p1
|
|
|
|
.line 4
|
|
:cond_1
|
|
sget-object v1, Lcom/google/common/math/LongMath;->biggestBinomials:[I
|
|
|
|
array-length v2, v1
|
|
|
|
if-ge p1, v2, :cond_2
|
|
|
|
aget v1, v1, p1
|
|
|
|
if-gt p0, v1, :cond_2
|
|
|
|
.line 5
|
|
invoke-static {p0, p1}, Lcom/google/common/math/LongMath;->binomial(II)J
|
|
|
|
move-result-wide p0
|
|
|
|
invoke-static {p0, p1}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
|
|
.line 6
|
|
:cond_2
|
|
sget-object v1, Ljava/math/BigInteger;->ONE:Ljava/math/BigInteger;
|
|
|
|
int-to-long v2, p0
|
|
|
|
const-wide/16 v4, 0x1
|
|
|
|
.line 7
|
|
sget-object v6, Ljava/math/RoundingMode;->CEILING:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {v2, v3, v6}, Lcom/google/common/math/LongMath;->log2(JLjava/math/RoundingMode;)I
|
|
|
|
move-result v6
|
|
|
|
:goto_1
|
|
move v7, v6
|
|
|
|
:goto_2
|
|
if-ge v0, p1, :cond_4
|
|
|
|
sub-int v8, p0, v0
|
|
|
|
add-int/lit8 v0, v0, 0x1
|
|
|
|
add-int/2addr v7, v6
|
|
|
|
const/16 v9, 0x3f
|
|
|
|
if-lt v7, v9, :cond_3
|
|
|
|
.line 8
|
|
invoke-static {v2, v3}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object v2
|
|
|
|
invoke-virtual {v1, v2}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v1
|
|
|
|
.line 9
|
|
invoke-static {v4, v5}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object v2
|
|
|
|
invoke-virtual {v1, v2}, Ljava/math/BigInteger;->divide(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v1
|
|
|
|
int-to-long v2, v8
|
|
|
|
int-to-long v4, v0
|
|
|
|
goto :goto_1
|
|
|
|
:cond_3
|
|
int-to-long v8, v8
|
|
|
|
mul-long/2addr v2, v8
|
|
|
|
int-to-long v8, v0
|
|
|
|
mul-long/2addr v4, v8
|
|
|
|
goto :goto_2
|
|
|
|
.line 10
|
|
:cond_4
|
|
invoke-static {v2, v3}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
invoke-virtual {v1, p0}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
.line 11
|
|
invoke-static {v4, v5}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-virtual {p0, p1}, Ljava/math/BigInteger;->divide(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
.end method
|
|
|
|
.method public static ceilingPowerOfTwo(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
.locals 2
|
|
.annotation build Lcom/google/common/annotations/Beta;
|
|
.end annotation
|
|
|
|
.line 1
|
|
sget-object v0, Ljava/math/BigInteger;->ZERO:Ljava/math/BigInteger;
|
|
|
|
sget-object v1, Ljava/math/RoundingMode;->CEILING:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {p0, v1}, Lcom/google/common/math/BigIntegerMath;->log2(Ljava/math/BigInteger;Ljava/math/RoundingMode;)I
|
|
|
|
move-result p0
|
|
|
|
invoke-virtual {v0, p0}, Ljava/math/BigInteger;->setBit(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
.end method
|
|
|
|
.method public static divide(Ljava/math/BigInteger;Ljava/math/BigInteger;Ljava/math/RoundingMode;)Ljava/math/BigInteger;
|
|
.locals 1
|
|
.annotation build Lcom/google/common/annotations/GwtIncompatible;
|
|
.end annotation
|
|
|
|
.line 1
|
|
new-instance v0, Ljava/math/BigDecimal;
|
|
|
|
invoke-direct {v0, p0}, Ljava/math/BigDecimal;-><init>(Ljava/math/BigInteger;)V
|
|
|
|
.line 2
|
|
new-instance p0, Ljava/math/BigDecimal;
|
|
|
|
invoke-direct {p0, p1}, Ljava/math/BigDecimal;-><init>(Ljava/math/BigInteger;)V
|
|
|
|
const/4 p1, 0x0
|
|
|
|
.line 3
|
|
invoke-virtual {v0, p0, p1, p2}, Ljava/math/BigDecimal;->divide(Ljava/math/BigDecimal;ILjava/math/RoundingMode;)Ljava/math/BigDecimal;
|
|
|
|
move-result-object p0
|
|
|
|
invoke-virtual {p0}, Ljava/math/BigDecimal;->toBigIntegerExact()Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
.end method
|
|
|
|
.method public static factorial(I)Ljava/math/BigInteger;
|
|
.locals 17
|
|
|
|
move/from16 v0, p0
|
|
|
|
const-string v1, "n"
|
|
|
|
.line 1
|
|
invoke-static {v1, v0}, Lcom/google/common/math/MathPreconditions;->checkNonNegative(Ljava/lang/String;I)I
|
|
|
|
.line 2
|
|
sget-object v1, Lcom/google/common/math/LongMath;->factorials:[J
|
|
|
|
array-length v2, v1
|
|
|
|
if-ge v0, v2, :cond_0
|
|
|
|
.line 3
|
|
aget-wide v0, v1, v0
|
|
|
|
invoke-static {v0, v1}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
return-object v0
|
|
|
|
.line 4
|
|
:cond_0
|
|
sget-object v2, Ljava/math/RoundingMode;->CEILING:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {v0, v2}, Lcom/google/common/math/IntMath;->log2(ILjava/math/RoundingMode;)I
|
|
|
|
move-result v2
|
|
|
|
mul-int/2addr v2, v0
|
|
|
|
sget-object v3, Ljava/math/RoundingMode;->CEILING:Ljava/math/RoundingMode;
|
|
|
|
const/16 v4, 0x40
|
|
|
|
invoke-static {v2, v4, v3}, Lcom/google/common/math/IntMath;->divide(IILjava/math/RoundingMode;)I
|
|
|
|
move-result v2
|
|
|
|
.line 5
|
|
new-instance v3, Ljava/util/ArrayList;
|
|
|
|
invoke-direct {v3, v2}, Ljava/util/ArrayList;-><init>(I)V
|
|
|
|
.line 6
|
|
array-length v2, v1
|
|
|
|
add-int/lit8 v5, v2, -0x1
|
|
|
|
.line 7
|
|
aget-wide v5, v1, v5
|
|
|
|
.line 8
|
|
invoke-static {v5, v6}, Ljava/lang/Long;->numberOfTrailingZeros(J)I
|
|
|
|
move-result v1
|
|
|
|
shr-long/2addr v5, v1
|
|
|
|
.line 9
|
|
sget-object v7, Ljava/math/RoundingMode;->FLOOR:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {v5, v6, v7}, Lcom/google/common/math/LongMath;->log2(JLjava/math/RoundingMode;)I
|
|
|
|
move-result v7
|
|
|
|
const/4 v8, 0x1
|
|
|
|
add-int/2addr v7, v8
|
|
|
|
int-to-long v9, v2
|
|
|
|
.line 10
|
|
sget-object v2, Ljava/math/RoundingMode;->FLOOR:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {v9, v10, v2}, Lcom/google/common/math/LongMath;->log2(JLjava/math/RoundingMode;)I
|
|
|
|
move-result v2
|
|
|
|
add-int/2addr v2, v8
|
|
|
|
add-int/lit8 v11, v2, -0x1
|
|
|
|
shl-int v11, v8, v11
|
|
|
|
:goto_0
|
|
int-to-long v12, v0
|
|
|
|
cmp-long v12, v9, v12
|
|
|
|
if-gtz v12, :cond_3
|
|
|
|
int-to-long v13, v11
|
|
|
|
and-long v12, v9, v13
|
|
|
|
const-wide/16 v15, 0x0
|
|
|
|
cmp-long v12, v12, v15
|
|
|
|
if-eqz v12, :cond_1
|
|
|
|
shl-int/lit8 v11, v11, 0x1
|
|
|
|
add-int/lit8 v2, v2, 0x1
|
|
|
|
.line 11
|
|
:cond_1
|
|
invoke-static {v9, v10}, Ljava/lang/Long;->numberOfTrailingZeros(J)I
|
|
|
|
move-result v12
|
|
|
|
shr-long v13, v9, v12
|
|
|
|
add-int/2addr v1, v12
|
|
|
|
sub-int v12, v2, v12
|
|
|
|
add-int/2addr v12, v7
|
|
|
|
if-lt v12, v4, :cond_2
|
|
|
|
.line 12
|
|
invoke-static {v5, v6}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object v5
|
|
|
|
invoke-virtual {v3, v5}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z
|
|
|
|
const-wide/16 v5, 0x1
|
|
|
|
:cond_2
|
|
mul-long/2addr v5, v13
|
|
|
|
.line 13
|
|
sget-object v7, Ljava/math/RoundingMode;->FLOOR:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {v5, v6, v7}, Lcom/google/common/math/LongMath;->log2(JLjava/math/RoundingMode;)I
|
|
|
|
move-result v7
|
|
|
|
add-int/2addr v7, v8
|
|
|
|
const-wide/16 v12, 0x1
|
|
|
|
add-long/2addr v9, v12
|
|
|
|
goto :goto_0
|
|
|
|
:cond_3
|
|
const-wide/16 v12, 0x1
|
|
|
|
cmp-long v0, v5, v12
|
|
|
|
if-lez v0, :cond_4
|
|
|
|
.line 14
|
|
invoke-static {v5, v6}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
invoke-virtual {v3, v0}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z
|
|
|
|
.line 15
|
|
:cond_4
|
|
invoke-static {v3}, Lcom/google/common/math/BigIntegerMath;->listProduct(Ljava/util/List;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
invoke-virtual {v0, v1}, Ljava/math/BigInteger;->shiftLeft(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
return-object v0
|
|
.end method
|
|
|
|
.method public static fitsInLong(Ljava/math/BigInteger;)Z
|
|
.locals 1
|
|
.annotation build Lcom/google/common/annotations/GwtIncompatible;
|
|
.end annotation
|
|
|
|
.line 1
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->bitLength()I
|
|
|
|
move-result p0
|
|
|
|
const/16 v0, 0x3f
|
|
|
|
if-gt p0, v0, :cond_0
|
|
|
|
const/4 p0, 0x1
|
|
|
|
goto :goto_0
|
|
|
|
:cond_0
|
|
const/4 p0, 0x0
|
|
|
|
:goto_0
|
|
return p0
|
|
.end method
|
|
|
|
.method public static floorPowerOfTwo(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
.locals 2
|
|
.annotation build Lcom/google/common/annotations/Beta;
|
|
.end annotation
|
|
|
|
.line 1
|
|
sget-object v0, Ljava/math/BigInteger;->ZERO:Ljava/math/BigInteger;
|
|
|
|
sget-object v1, Ljava/math/RoundingMode;->FLOOR:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {p0, v1}, Lcom/google/common/math/BigIntegerMath;->log2(Ljava/math/BigInteger;Ljava/math/RoundingMode;)I
|
|
|
|
move-result p0
|
|
|
|
invoke-virtual {v0, p0}, Ljava/math/BigInteger;->setBit(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
.end method
|
|
|
|
.method public static isPowerOfTwo(Ljava/math/BigInteger;)Z
|
|
.locals 2
|
|
|
|
.line 1
|
|
invoke-static {p0}, Lcom/google/common/base/Preconditions;->checkNotNull(Ljava/lang/Object;)Ljava/lang/Object;
|
|
|
|
.line 2
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->signum()I
|
|
|
|
move-result v0
|
|
|
|
const/4 v1, 0x1
|
|
|
|
if-lez v0, :cond_0
|
|
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->getLowestSetBit()I
|
|
|
|
move-result v0
|
|
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->bitLength()I
|
|
|
|
move-result p0
|
|
|
|
sub-int/2addr p0, v1
|
|
|
|
if-ne v0, p0, :cond_0
|
|
|
|
goto :goto_0
|
|
|
|
:cond_0
|
|
const/4 v1, 0x0
|
|
|
|
:goto_0
|
|
return v1
|
|
.end method
|
|
|
|
.method public static listProduct(Ljava/util/List;)Ljava/math/BigInteger;
|
|
.locals 2
|
|
.annotation system Ldalvik/annotation/Signature;
|
|
value = {
|
|
"(",
|
|
"Ljava/util/List<",
|
|
"Ljava/math/BigInteger;",
|
|
">;)",
|
|
"Ljava/math/BigInteger;"
|
|
}
|
|
.end annotation
|
|
|
|
.line 1
|
|
invoke-interface {p0}, Ljava/util/List;->size()I
|
|
|
|
move-result v0
|
|
|
|
const/4 v1, 0x0
|
|
|
|
invoke-static {p0, v1, v0}, Lcom/google/common/math/BigIntegerMath;->listProduct(Ljava/util/List;II)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
.end method
|
|
|
|
.method public static listProduct(Ljava/util/List;II)Ljava/math/BigInteger;
|
|
.locals 4
|
|
.annotation system Ldalvik/annotation/Signature;
|
|
value = {
|
|
"(",
|
|
"Ljava/util/List<",
|
|
"Ljava/math/BigInteger;",
|
|
">;II)",
|
|
"Ljava/math/BigInteger;"
|
|
}
|
|
.end annotation
|
|
|
|
sub-int v0, p2, p1
|
|
|
|
if-eqz v0, :cond_3
|
|
|
|
const/4 v1, 0x1
|
|
|
|
if-eq v0, v1, :cond_2
|
|
|
|
const/4 v2, 0x2
|
|
|
|
if-eq v0, v2, :cond_1
|
|
|
|
const/4 v3, 0x3
|
|
|
|
if-eq v0, v3, :cond_0
|
|
|
|
add-int v0, p2, p1
|
|
|
|
ushr-int/2addr v0, v1
|
|
|
|
.line 2
|
|
invoke-static {p0, p1, v0}, Lcom/google/common/math/BigIntegerMath;->listProduct(Ljava/util/List;II)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-static {p0, v0, p2}, Lcom/google/common/math/BigIntegerMath;->listProduct(Ljava/util/List;II)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
invoke-virtual {p1, p0}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
|
|
.line 3
|
|
:cond_0
|
|
invoke-interface {p0, p1}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object p2
|
|
|
|
check-cast p2, Ljava/math/BigInteger;
|
|
|
|
add-int/lit8 v0, p1, 0x1
|
|
|
|
invoke-interface {p0, v0}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object v0
|
|
|
|
check-cast v0, Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {p2, v0}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p2
|
|
|
|
add-int/2addr p1, v2
|
|
|
|
invoke-interface {p0, p1}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object p0
|
|
|
|
check-cast p0, Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {p2, p0}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
|
|
.line 4
|
|
:cond_1
|
|
invoke-interface {p0, p1}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object p2
|
|
|
|
check-cast p2, Ljava/math/BigInteger;
|
|
|
|
add-int/2addr p1, v1
|
|
|
|
invoke-interface {p0, p1}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object p0
|
|
|
|
check-cast p0, Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {p2, p0}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
|
|
.line 5
|
|
:cond_2
|
|
invoke-interface {p0, p1}, Ljava/util/List;->get(I)Ljava/lang/Object;
|
|
|
|
move-result-object p0
|
|
|
|
check-cast p0, Ljava/math/BigInteger;
|
|
|
|
return-object p0
|
|
|
|
.line 6
|
|
:cond_3
|
|
sget-object p0, Ljava/math/BigInteger;->ONE:Ljava/math/BigInteger;
|
|
|
|
return-object p0
|
|
.end method
|
|
|
|
.method public static log10(Ljava/math/BigInteger;Ljava/math/RoundingMode;)I
|
|
.locals 7
|
|
.annotation build Lcom/google/common/annotations/GwtIncompatible;
|
|
.end annotation
|
|
|
|
const-string v0, "x"
|
|
|
|
.line 1
|
|
invoke-static {v0, p0}, Lcom/google/common/math/MathPreconditions;->checkPositive(Ljava/lang/String;Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
.line 2
|
|
invoke-static {p0}, Lcom/google/common/math/BigIntegerMath;->fitsInLong(Ljava/math/BigInteger;)Z
|
|
|
|
move-result v0
|
|
|
|
if-eqz v0, :cond_0
|
|
|
|
.line 3
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->longValue()J
|
|
|
|
move-result-wide v0
|
|
|
|
invoke-static {v0, v1, p1}, Lcom/google/common/math/LongMath;->log10(JLjava/math/RoundingMode;)I
|
|
|
|
move-result p0
|
|
|
|
return p0
|
|
|
|
.line 4
|
|
:cond_0
|
|
sget-object v0, Ljava/math/RoundingMode;->FLOOR:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {p0, v0}, Lcom/google/common/math/BigIntegerMath;->log2(Ljava/math/BigInteger;Ljava/math/RoundingMode;)I
|
|
|
|
move-result v0
|
|
|
|
int-to-double v0, v0
|
|
|
|
sget-wide v2, Lcom/google/common/math/BigIntegerMath;->LN_2:D
|
|
|
|
mul-double/2addr v0, v2
|
|
|
|
sget-wide v2, Lcom/google/common/math/BigIntegerMath;->LN_10:D
|
|
|
|
div-double/2addr v0, v2
|
|
|
|
double-to-int v0, v0
|
|
|
|
.line 5
|
|
sget-object v1, Ljava/math/BigInteger;->TEN:Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {v1, v0}, Ljava/math/BigInteger;->pow(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object v1
|
|
|
|
.line 6
|
|
invoke-virtual {v1, p0}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
|
|
|
|
move-result v2
|
|
|
|
if-lez v2, :cond_2
|
|
|
|
:cond_1
|
|
add-int/lit8 v0, v0, -0x1
|
|
|
|
.line 7
|
|
sget-object v2, Ljava/math/BigInteger;->TEN:Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {v1, v2}, Ljava/math/BigInteger;->divide(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v1
|
|
|
|
.line 8
|
|
invoke-virtual {v1, p0}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
|
|
|
|
move-result v2
|
|
|
|
if-gtz v2, :cond_1
|
|
|
|
goto :goto_1
|
|
|
|
.line 9
|
|
:cond_2
|
|
sget-object v3, Ljava/math/BigInteger;->TEN:Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {v3, v1}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v3
|
|
|
|
.line 10
|
|
invoke-virtual {v3, p0}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
|
|
|
|
move-result v4
|
|
|
|
move v5, v4
|
|
|
|
move v4, v2
|
|
|
|
move v2, v5
|
|
|
|
:goto_0
|
|
if-gtz v2, :cond_3
|
|
|
|
add-int/lit8 v0, v0, 0x1
|
|
|
|
.line 11
|
|
sget-object v1, Ljava/math/BigInteger;->TEN:Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {v1, v3}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v1
|
|
|
|
.line 12
|
|
invoke-virtual {v1, p0}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
|
|
|
|
move-result v4
|
|
|
|
move-object v5, v3
|
|
|
|
move-object v3, v1
|
|
|
|
move-object v1, v5
|
|
|
|
move v6, v4
|
|
|
|
move v4, v2
|
|
|
|
move v2, v6
|
|
|
|
goto :goto_0
|
|
|
|
:cond_3
|
|
move v2, v4
|
|
|
|
.line 13
|
|
:goto_1
|
|
sget-object v3, Lcom/google/common/math/BigIntegerMath$1;->$SwitchMap$java$math$RoundingMode:[I
|
|
|
|
invoke-virtual {p1}, Ljava/math/RoundingMode;->ordinal()I
|
|
|
|
move-result p1
|
|
|
|
aget p1, v3, p1
|
|
|
|
packed-switch p1, :pswitch_data_0
|
|
|
|
.line 14
|
|
new-instance p0, Ljava/lang/AssertionError;
|
|
|
|
invoke-direct {p0}, Ljava/lang/AssertionError;-><init>()V
|
|
|
|
throw p0
|
|
|
|
:pswitch_0
|
|
const/4 p1, 0x2
|
|
|
|
.line 15
|
|
invoke-virtual {p0, p1}, Ljava/math/BigInteger;->pow(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
.line 16
|
|
invoke-virtual {v1, p1}, Ljava/math/BigInteger;->pow(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
sget-object v1, Ljava/math/BigInteger;->TEN:Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {p1, v1}, Ljava/math/BigInteger;->multiply(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
.line 17
|
|
invoke-virtual {p0, p1}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
|
|
|
|
move-result p0
|
|
|
|
if-gtz p0, :cond_4
|
|
|
|
goto :goto_2
|
|
|
|
:cond_4
|
|
add-int/lit8 v0, v0, 0x1
|
|
|
|
:goto_2
|
|
return v0
|
|
|
|
.line 18
|
|
:pswitch_1
|
|
invoke-virtual {v1, p0}, Ljava/math/BigInteger;->equals(Ljava/lang/Object;)Z
|
|
|
|
move-result p0
|
|
|
|
if-eqz p0, :cond_5
|
|
|
|
goto :goto_3
|
|
|
|
:cond_5
|
|
add-int/lit8 v0, v0, 0x1
|
|
|
|
:goto_3
|
|
return v0
|
|
|
|
:pswitch_2
|
|
if-nez v2, :cond_6
|
|
|
|
const/4 p0, 0x1
|
|
|
|
goto :goto_4
|
|
|
|
:cond_6
|
|
const/4 p0, 0x0
|
|
|
|
.line 19
|
|
:goto_4
|
|
invoke-static {p0}, Lcom/google/common/math/MathPreconditions;->checkRoundingUnnecessary(Z)V
|
|
|
|
:pswitch_3
|
|
return v0
|
|
|
|
nop
|
|
|
|
:pswitch_data_0
|
|
.packed-switch 0x1
|
|
:pswitch_2
|
|
:pswitch_3
|
|
:pswitch_3
|
|
:pswitch_1
|
|
:pswitch_1
|
|
:pswitch_0
|
|
:pswitch_0
|
|
:pswitch_0
|
|
.end packed-switch
|
|
.end method
|
|
|
|
.method public static log2(Ljava/math/BigInteger;Ljava/math/RoundingMode;)I
|
|
.locals 2
|
|
|
|
.line 1
|
|
invoke-static {p0}, Lcom/google/common/base/Preconditions;->checkNotNull(Ljava/lang/Object;)Ljava/lang/Object;
|
|
|
|
move-result-object v0
|
|
|
|
check-cast v0, Ljava/math/BigInteger;
|
|
|
|
const-string v1, "x"
|
|
|
|
invoke-static {v1, v0}, Lcom/google/common/math/MathPreconditions;->checkPositive(Ljava/lang/String;Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
.line 2
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->bitLength()I
|
|
|
|
move-result v0
|
|
|
|
add-int/lit8 v0, v0, -0x1
|
|
|
|
.line 3
|
|
sget-object v1, Lcom/google/common/math/BigIntegerMath$1;->$SwitchMap$java$math$RoundingMode:[I
|
|
|
|
invoke-virtual {p1}, Ljava/math/RoundingMode;->ordinal()I
|
|
|
|
move-result p1
|
|
|
|
aget p1, v1, p1
|
|
|
|
packed-switch p1, :pswitch_data_0
|
|
|
|
.line 4
|
|
new-instance p0, Ljava/lang/AssertionError;
|
|
|
|
invoke-direct {p0}, Ljava/lang/AssertionError;-><init>()V
|
|
|
|
throw p0
|
|
|
|
:pswitch_0
|
|
const/16 p1, 0x100
|
|
|
|
if-ge v0, p1, :cond_1
|
|
|
|
.line 5
|
|
sget-object p1, Lcom/google/common/math/BigIntegerMath;->SQRT2_PRECOMPUTED_BITS:Ljava/math/BigInteger;
|
|
|
|
rsub-int v1, v0, 0x100
|
|
|
|
.line 6
|
|
invoke-virtual {p1, v1}, Ljava/math/BigInteger;->shiftRight(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
.line 7
|
|
invoke-virtual {p0, p1}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
|
|
|
|
move-result p0
|
|
|
|
if-gtz p0, :cond_0
|
|
|
|
return v0
|
|
|
|
:cond_0
|
|
add-int/lit8 v0, v0, 0x1
|
|
|
|
return v0
|
|
|
|
:cond_1
|
|
const/4 p1, 0x2
|
|
|
|
.line 8
|
|
invoke-virtual {p0, p1}, Ljava/math/BigInteger;->pow(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
.line 9
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->bitLength()I
|
|
|
|
move-result p0
|
|
|
|
add-int/lit8 p0, p0, -0x1
|
|
|
|
mul-int/lit8 p1, v0, 0x2
|
|
|
|
add-int/lit8 p1, p1, 0x1
|
|
|
|
if-ge p0, p1, :cond_2
|
|
|
|
goto :goto_0
|
|
|
|
:cond_2
|
|
add-int/lit8 v0, v0, 0x1
|
|
|
|
:goto_0
|
|
return v0
|
|
|
|
.line 10
|
|
:pswitch_1
|
|
invoke-static {p0}, Lcom/google/common/math/BigIntegerMath;->isPowerOfTwo(Ljava/math/BigInteger;)Z
|
|
|
|
move-result p0
|
|
|
|
if-eqz p0, :cond_3
|
|
|
|
goto :goto_1
|
|
|
|
:cond_3
|
|
add-int/lit8 v0, v0, 0x1
|
|
|
|
:goto_1
|
|
return v0
|
|
|
|
.line 11
|
|
:pswitch_2
|
|
invoke-static {p0}, Lcom/google/common/math/BigIntegerMath;->isPowerOfTwo(Ljava/math/BigInteger;)Z
|
|
|
|
move-result p0
|
|
|
|
invoke-static {p0}, Lcom/google/common/math/MathPreconditions;->checkRoundingUnnecessary(Z)V
|
|
|
|
:pswitch_3
|
|
return v0
|
|
|
|
nop
|
|
|
|
:pswitch_data_0
|
|
.packed-switch 0x1
|
|
:pswitch_2
|
|
:pswitch_3
|
|
:pswitch_3
|
|
:pswitch_1
|
|
:pswitch_1
|
|
:pswitch_0
|
|
:pswitch_0
|
|
:pswitch_0
|
|
.end packed-switch
|
|
.end method
|
|
|
|
.method public static roundToDouble(Ljava/math/BigInteger;Ljava/math/RoundingMode;)D
|
|
.locals 1
|
|
.annotation build Lcom/google/common/annotations/GwtIncompatible;
|
|
.end annotation
|
|
|
|
.line 1
|
|
sget-object v0, Lcom/google/common/math/BigIntegerMath$BigIntegerToDoubleRounder;->INSTANCE:Lcom/google/common/math/BigIntegerMath$BigIntegerToDoubleRounder;
|
|
|
|
invoke-virtual {v0, p0, p1}, Lcom/google/common/math/ToDoubleRounder;->roundToDouble(Ljava/lang/Number;Ljava/math/RoundingMode;)D
|
|
|
|
move-result-wide p0
|
|
|
|
return-wide p0
|
|
.end method
|
|
|
|
.method public static sqrt(Ljava/math/BigInteger;Ljava/math/RoundingMode;)Ljava/math/BigInteger;
|
|
.locals 3
|
|
.annotation build Lcom/google/common/annotations/GwtIncompatible;
|
|
.end annotation
|
|
|
|
const-string v0, "x"
|
|
|
|
.line 1
|
|
invoke-static {v0, p0}, Lcom/google/common/math/MathPreconditions;->checkNonNegative(Ljava/lang/String;Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
.line 2
|
|
invoke-static {p0}, Lcom/google/common/math/BigIntegerMath;->fitsInLong(Ljava/math/BigInteger;)Z
|
|
|
|
move-result v0
|
|
|
|
if-eqz v0, :cond_0
|
|
|
|
.line 3
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->longValue()J
|
|
|
|
move-result-wide v0
|
|
|
|
invoke-static {v0, v1, p1}, Lcom/google/common/math/LongMath;->sqrt(JLjava/math/RoundingMode;)J
|
|
|
|
move-result-wide p0
|
|
|
|
invoke-static {p0, p1}, Ljava/math/BigInteger;->valueOf(J)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
|
|
.line 4
|
|
:cond_0
|
|
invoke-static {p0}, Lcom/google/common/math/BigIntegerMath;->sqrtFloor(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
.line 5
|
|
sget-object v1, Lcom/google/common/math/BigIntegerMath$1;->$SwitchMap$java$math$RoundingMode:[I
|
|
|
|
invoke-virtual {p1}, Ljava/math/RoundingMode;->ordinal()I
|
|
|
|
move-result p1
|
|
|
|
aget p1, v1, p1
|
|
|
|
const/4 v1, 0x2
|
|
|
|
packed-switch p1, :pswitch_data_0
|
|
|
|
.line 6
|
|
new-instance p0, Ljava/lang/AssertionError;
|
|
|
|
invoke-direct {p0}, Ljava/lang/AssertionError;-><init>()V
|
|
|
|
throw p0
|
|
|
|
.line 7
|
|
:pswitch_0
|
|
invoke-virtual {v0, v1}, Ljava/math/BigInteger;->pow(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-virtual {p1, v0}, Ljava/math/BigInteger;->add(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
.line 8
|
|
invoke-virtual {p1, p0}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
|
|
|
|
move-result p0
|
|
|
|
if-ltz p0, :cond_1
|
|
|
|
goto :goto_0
|
|
|
|
:cond_1
|
|
sget-object p0, Ljava/math/BigInteger;->ONE:Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {v0, p0}, Ljava/math/BigInteger;->add(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
:goto_0
|
|
return-object v0
|
|
|
|
.line 9
|
|
:pswitch_1
|
|
invoke-virtual {v0}, Ljava/math/BigInteger;->intValue()I
|
|
|
|
move-result p1
|
|
|
|
mul-int/2addr p1, p1
|
|
|
|
.line 10
|
|
invoke-virtual {p0}, Ljava/math/BigInteger;->intValue()I
|
|
|
|
move-result v2
|
|
|
|
if-ne p1, v2, :cond_2
|
|
|
|
.line 11
|
|
invoke-virtual {v0, v1}, Ljava/math/BigInteger;->pow(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-virtual {p1, p0}, Ljava/math/BigInteger;->equals(Ljava/lang/Object;)Z
|
|
|
|
move-result p0
|
|
|
|
if-eqz p0, :cond_2
|
|
|
|
const/4 p0, 0x1
|
|
|
|
goto :goto_1
|
|
|
|
:cond_2
|
|
const/4 p0, 0x0
|
|
|
|
:goto_1
|
|
if-eqz p0, :cond_3
|
|
|
|
goto :goto_2
|
|
|
|
.line 12
|
|
:cond_3
|
|
sget-object p0, Ljava/math/BigInteger;->ONE:Ljava/math/BigInteger;
|
|
|
|
invoke-virtual {v0, p0}, Ljava/math/BigInteger;->add(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
:goto_2
|
|
return-object v0
|
|
|
|
.line 13
|
|
:pswitch_2
|
|
invoke-virtual {v0, v1}, Ljava/math/BigInteger;->pow(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object p1
|
|
|
|
invoke-virtual {p1, p0}, Ljava/math/BigInteger;->equals(Ljava/lang/Object;)Z
|
|
|
|
move-result p0
|
|
|
|
invoke-static {p0}, Lcom/google/common/math/MathPreconditions;->checkRoundingUnnecessary(Z)V
|
|
|
|
:pswitch_3
|
|
return-object v0
|
|
|
|
:pswitch_data_0
|
|
.packed-switch 0x1
|
|
:pswitch_2
|
|
:pswitch_3
|
|
:pswitch_3
|
|
:pswitch_1
|
|
:pswitch_1
|
|
:pswitch_0
|
|
:pswitch_0
|
|
:pswitch_0
|
|
.end packed-switch
|
|
.end method
|
|
|
|
.method private static sqrtApproxWithDoubles(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
.locals 2
|
|
.annotation build Lcom/google/common/annotations/GwtIncompatible;
|
|
.end annotation
|
|
|
|
.line 1
|
|
invoke-static {p0}, Lcom/google/common/math/DoubleUtils;->bigToDouble(Ljava/math/BigInteger;)D
|
|
|
|
move-result-wide v0
|
|
|
|
invoke-static {v0, v1}, Ljava/lang/Math;->sqrt(D)D
|
|
|
|
move-result-wide v0
|
|
|
|
sget-object p0, Ljava/math/RoundingMode;->HALF_EVEN:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {v0, v1, p0}, Lcom/google/common/math/DoubleMath;->roundToBigInteger(DLjava/math/RoundingMode;)Ljava/math/BigInteger;
|
|
|
|
move-result-object p0
|
|
|
|
return-object p0
|
|
.end method
|
|
|
|
.method private static sqrtFloor(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
.locals 4
|
|
.annotation build Lcom/google/common/annotations/GwtIncompatible;
|
|
.end annotation
|
|
|
|
.line 1
|
|
sget-object v0, Ljava/math/RoundingMode;->FLOOR:Ljava/math/RoundingMode;
|
|
|
|
invoke-static {p0, v0}, Lcom/google/common/math/BigIntegerMath;->log2(Ljava/math/BigInteger;Ljava/math/RoundingMode;)I
|
|
|
|
move-result v0
|
|
|
|
const/4 v1, 0x1
|
|
|
|
const/16 v2, 0x3ff
|
|
|
|
if-ge v0, v2, :cond_0
|
|
|
|
.line 2
|
|
invoke-static {p0}, Lcom/google/common/math/BigIntegerMath;->sqrtApproxWithDoubles(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
goto :goto_0
|
|
|
|
:cond_0
|
|
add-int/lit8 v0, v0, -0x34
|
|
|
|
and-int/lit8 v0, v0, -0x2
|
|
|
|
.line 3
|
|
invoke-virtual {p0, v0}, Ljava/math/BigInteger;->shiftRight(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object v2
|
|
|
|
invoke-static {v2}, Lcom/google/common/math/BigIntegerMath;->sqrtApproxWithDoubles(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v2
|
|
|
|
shr-int/2addr v0, v1
|
|
|
|
invoke-virtual {v2, v0}, Ljava/math/BigInteger;->shiftLeft(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
.line 4
|
|
:goto_0
|
|
invoke-virtual {p0, v0}, Ljava/math/BigInteger;->divide(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v2
|
|
|
|
invoke-virtual {v0, v2}, Ljava/math/BigInteger;->add(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v2
|
|
|
|
invoke-virtual {v2, v1}, Ljava/math/BigInteger;->shiftRight(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object v2
|
|
|
|
.line 5
|
|
invoke-virtual {v0, v2}, Ljava/math/BigInteger;->equals(Ljava/lang/Object;)Z
|
|
|
|
move-result v3
|
|
|
|
if-eqz v3, :cond_1
|
|
|
|
return-object v0
|
|
|
|
.line 6
|
|
:cond_1
|
|
:goto_1
|
|
invoke-virtual {p0, v2}, Ljava/math/BigInteger;->divide(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
invoke-virtual {v2, v0}, Ljava/math/BigInteger;->add(Ljava/math/BigInteger;)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
invoke-virtual {v0, v1}, Ljava/math/BigInteger;->shiftRight(I)Ljava/math/BigInteger;
|
|
|
|
move-result-object v0
|
|
|
|
.line 7
|
|
invoke-virtual {v0, v2}, Ljava/math/BigInteger;->compareTo(Ljava/math/BigInteger;)I
|
|
|
|
move-result v3
|
|
|
|
if-ltz v3, :cond_2
|
|
|
|
return-object v2
|
|
|
|
:cond_2
|
|
move-object v2, v0
|
|
|
|
goto :goto_1
|
|
.end method
|