package j$.time.format;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Objects;

/* JADX INFO: renamed from: j$.time.format.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes2.dex */
final class C2297g extends C2300j {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final boolean f19229g;

    C2297g(j$.time.temporal.a aVar, int i6, int i7, boolean z6) {
        this(aVar, i6, i7, z6, 0);
        Objects.requireNonNull(aVar, "field");
        if (!aVar.B().g()) {
            throw new IllegalArgumentException("Field must have a fixed set of values: " + aVar);
        }
        if (i6 < 0 || i6 > 9) {
            throw new IllegalArgumentException("Minimum width must be from 0 to 9 inclusive but was " + i6);
        }
        if (i7 < 1 || i7 > 9) {
            throw new IllegalArgumentException("Maximum width must be from 1 to 9 inclusive but was " + i7);
        }
        if (i7 >= i6) {
            return;
        }
        throw new IllegalArgumentException("Maximum width must exceed or equal the minimum width but " + i7 + " < " + i6);
    }

    C2297g(j$.time.temporal.s sVar, int i6, int i7, boolean z6, int i8) {
        super(sVar, i6, i7, H.NOT_NEGATIVE, i8);
        this.f19229g = z6;
    }

    @Override // j$.time.format.C2300j
    final C2300j e() {
        if (this.f19237e == -1) {
            return this;
        }
        return new C2297g(this.f19233a, this.f19234b, this.f19235c, this.f19229g, -1);
    }

    @Override // j$.time.format.C2300j
    final C2300j f(int i6) {
        return new C2297g(this.f19233a, this.f19234b, this.f19235c, this.f19229g, this.f19237e + i6);
    }

    @Override // j$.time.format.C2300j
    final boolean c(w wVar) {
        return wVar.l() && this.f19234b == this.f19235c && !this.f19229g;
    }

    @Override // j$.time.format.C2300j, j$.time.format.InterfaceC2296f
    public final boolean p(z zVar, StringBuilder sb) {
        j$.time.temporal.s sVar = this.f19233a;
        Long lE = zVar.e(sVar);
        if (lE == null) {
            return false;
        }
        D dB = zVar.b();
        long jLongValue = lE.longValue();
        j$.time.temporal.x xVarB = sVar.B();
        xVarB.b(jLongValue, sVar);
        BigDecimal bigDecimalValueOf = BigDecimal.valueOf(xVarB.e());
        BigDecimal bigDecimalAdd = BigDecimal.valueOf(xVarB.d()).subtract(bigDecimalValueOf).add(BigDecimal.ONE);
        BigDecimal bigDecimalSubtract = BigDecimal.valueOf(jLongValue).subtract(bigDecimalValueOf);
        RoundingMode roundingMode = RoundingMode.FLOOR;
        BigDecimal bigDecimalDivide = bigDecimalSubtract.divide(bigDecimalAdd, 9, roundingMode);
        BigDecimal bigDecimal = BigDecimal.ZERO;
        if (bigDecimalDivide.compareTo(bigDecimal) != 0) {
            bigDecimal = bigDecimalDivide.signum() == 0 ? new BigDecimal(BigInteger.ZERO, 0) : bigDecimalDivide.stripTrailingZeros();
        }
        int iScale = bigDecimal.scale();
        boolean z6 = this.f19229g;
        int i6 = this.f19234b;
        if (iScale != 0) {
            String strSubstring = bigDecimal.setScale(Math.min(Math.max(bigDecimal.scale(), i6), this.f19235c), roundingMode).toPlainString().substring(2);
            dB.getClass();
            if (z6) {
                sb.append('.');
            }
            sb.append(strSubstring);
            return true;
        }
        if (i6 <= 0) {
            return true;
        }
        if (z6) {
            dB.getClass();
            sb.append('.');
        }
        for (int i7 = 0; i7 < i6; i7++) {
            dB.getClass();
            sb.append('0');
        }
        return true;
    }

    @Override // j$.time.format.C2300j, j$.time.format.InterfaceC2296f
    public final int r(w wVar, CharSequence charSequence, int i6) {
        int i7 = (wVar.l() || c(wVar)) ? this.f19234b : 0;
        int i8 = (wVar.l() || c(wVar)) ? this.f19235c : 9;
        int length = charSequence.length();
        if (i6 != length) {
            if (this.f19229g) {
                char cCharAt = charSequence.charAt(i6);
                wVar.g().getClass();
                if (cCharAt == '.') {
                    i6++;
                } else if (i7 > 0) {
                    return ~i6;
                }
            }
            int i9 = i6;
            int i10 = i7 + i9;
            if (i10 > length) {
                return ~i9;
            }
            int iMin = Math.min(i8 + i9, length);
            int i11 = 0;
            int i12 = i9;
            while (true) {
                if (i12 >= iMin) {
                    break;
                }
                int i13 = i12 + 1;
                int iA = wVar.g().a(charSequence.charAt(i12));
                if (iA >= 0) {
                    i11 = (i11 * 10) + iA;
                    i12 = i13;
                } else if (i13 < i10) {
                    return ~i9;
                }
            }
            BigDecimal bigDecimalMovePointLeft = new BigDecimal(i11).movePointLeft(i12 - i9);
            j$.time.temporal.x xVarB = this.f19233a.B();
            BigDecimal bigDecimalValueOf = BigDecimal.valueOf(xVarB.e());
            return wVar.o(this.f19233a, bigDecimalMovePointLeft.multiply(BigDecimal.valueOf(xVarB.d()).subtract(bigDecimalValueOf).add(BigDecimal.ONE)).setScale(0, RoundingMode.FLOOR).add(bigDecimalValueOf).longValueExact(), i9, i12);
        }
        if (i7 > 0) {
            return ~i6;
        }
        return i6;
    }

    @Override // j$.time.format.C2300j
    public final String toString() {
        return "Fraction(" + this.f19233a + "," + this.f19234b + "," + this.f19235c + (this.f19229g ? ",DecimalPoint" : "") + ")";
    }
}
