package T4;

import A4.g;
import S4.p;
import androidx.media3.common.PlaybackException;
import androidx.media3.exoplayer.upstream.CmcdData;
import e4.C;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes3.dex */
public final class b implements Comparable {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final a f6709b = new a();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final long f6710c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final long f6711d;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final long f6712a;

    static {
        int i6 = c.f6713a;
        f6710c = C.w(4611686018427387903L);
        f6711d = C.w(-4611686018427387903L);
    }

    public static final long a(long j4, long j6) {
        long j7 = PlaybackException.CUSTOM_ERROR_CODE_BASE;
        long j8 = j6 / j7;
        long j9 = j4 + j8;
        if (-4611686018426L > j9 || j9 >= 4611686018427L) {
            return C.w(L4.a.x(j9, -4611686018427387903L, 4611686018427387903L));
        }
        return C.y((j9 * j7) + (j6 - (j8 * j7)));
    }

    public static final void b(StringBuilder sb, int i6, int i7, int i8, String str, boolean z6) {
        sb.append(i6);
        if (i7 != 0) {
            sb.append('.');
            String strV0 = p.V0(i8, String.valueOf(i7));
            int i9 = -1;
            int length = strV0.length() - 1;
            if (length >= 0) {
                while (true) {
                    int i10 = length - 1;
                    if (strV0.charAt(length) != '0') {
                        i9 = length;
                        break;
                    } else if (i10 < 0) {
                        break;
                    } else {
                        length = i10;
                    }
                }
            }
            int i11 = i9 + 1;
            if (z6 || i11 >= 3) {
                sb.append((CharSequence) strV0, 0, ((i9 + 3) / 3) * 3);
            } else {
                sb.append((CharSequence) strV0, 0, i11);
            }
        }
        sb.append(str);
    }

    public static int c(long j4, long j6) {
        long j7 = j4 ^ j6;
        if (j7 < 0 || (((int) j7) & 1) == 0) {
            return o.j(j4, j6);
        }
        int i6 = (((int) j4) & 1) - (((int) j6) & 1);
        return j4 < 0 ? -i6 : i6;
    }

    public static final long d(long j4) {
        return ((((int) j4) & 1) != 1 || f(j4)) ? h(j4, d.f6715c) : j4 >> 1;
    }

    public static final int e(long j4) {
        if (f(j4)) {
            return 0;
        }
        return (((int) j4) & 1) == 1 ? (int) (((j4 >> 1) % ((long) 1000)) * ((long) PlaybackException.CUSTOM_ERROR_CODE_BASE)) : (int) ((j4 >> 1) % ((long) 1000000000));
    }

    public static final boolean f(long j4) {
        return j4 == f6710c || j4 == f6711d;
    }

    public static final long g(long j4, long j6) {
        if (f(j4)) {
            if (!f(j6) || (j6 ^ j4) >= 0) {
                return j4;
            }
            throw new IllegalArgumentException("Summing infinite durations of different signs yields an undefined result.");
        }
        if (f(j6)) {
            return j6;
        }
        int i6 = ((int) j4) & 1;
        if (i6 != (((int) j6) & 1)) {
            return i6 == 1 ? a(j4 >> 1, j6 >> 1) : a(j6 >> 1, j4 >> 1);
        }
        long j7 = (j4 >> 1) + (j6 >> 1);
        return i6 == 0 ? (-4611686018426999999L > j7 || j7 >= 4611686018427000000L) ? C.w(j7 / ((long) PlaybackException.CUSTOM_ERROR_CODE_BASE)) : C.y(j7) : C.x(j7);
    }

    public static final long h(long j4, d unit) {
        o.h(unit, "unit");
        if (j4 == f6710c) {
            return Long.MAX_VALUE;
        }
        if (j4 == f6711d) {
            return Long.MIN_VALUE;
        }
        return g.x(j4 >> 1, (((int) j4) & 1) == 0 ? d.f6714b : d.f6715c, unit);
    }

    public static final long i(long j4) {
        long j6 = ((-(j4 >> 1)) << 1) + ((long) (((int) j4) & 1));
        int i6 = c.f6713a;
        return j6;
    }

    @Override // java.lang.Comparable
    public final int compareTo(Object obj) {
        return c(this.f6712a, ((b) obj).f6712a);
    }

    public final boolean equals(Object obj) {
        if (obj instanceof b) {
            return this.f6712a == ((b) obj).f6712a;
        }
        return false;
    }

    public final int hashCode() {
        return Long.hashCode(this.f6712a);
    }

    public final String toString() {
        long j4;
        int iH;
        long jI = this.f6712a;
        if (jI == 0) {
            return "0s";
        }
        if (jI == f6710c) {
            return "Infinity";
        }
        if (jI == f6711d) {
            return "-Infinity";
        }
        int i6 = 0;
        boolean z6 = jI < 0;
        StringBuilder sb = new StringBuilder();
        if (z6) {
            sb.append('-');
        }
        if (jI < 0) {
            jI = i(jI);
        }
        long jH = h(jI, d.f6719j);
        int iH2 = f(jI) ? 0 : (int) (h(jI, d.f6718f) % ((long) 24));
        if (f(jI)) {
            j4 = 0;
            iH = 0;
        } else {
            j4 = 0;
            iH = (int) (h(jI, d.f6717e) % ((long) 60));
        }
        int iH3 = f(jI) ? 0 : (int) (h(jI, d.f6716d) % ((long) 60));
        int iE = e(jI);
        boolean z7 = jH != j4;
        boolean z8 = iH2 != 0;
        boolean z9 = iH != 0;
        boolean z10 = (iH3 == 0 && iE == 0) ? false : true;
        if (z7) {
            sb.append(jH);
            sb.append('d');
            i6 = 1;
        }
        if (z8 || (z7 && (z9 || z10))) {
            int i7 = i6 + 1;
            if (i6 > 0) {
                sb.append(' ');
            }
            sb.append(iH2);
            sb.append('h');
            i6 = i7;
        }
        if (z9 || (z10 && (z8 || z7))) {
            int i8 = i6 + 1;
            if (i6 > 0) {
                sb.append(' ');
            }
            sb.append(iH);
            sb.append('m');
            i6 = i8;
        }
        if (z10) {
            int i9 = i6 + 1;
            if (i6 > 0) {
                sb.append(' ');
            }
            if (iH3 != 0 || z7 || z8 || z9) {
                b(sb, iH3, iE, 9, CmcdData.Factory.STREAMING_FORMAT_SS, false);
            } else if (iE >= 1000000) {
                b(sb, iE / PlaybackException.CUSTOM_ERROR_CODE_BASE, iE % PlaybackException.CUSTOM_ERROR_CODE_BASE, 6, "ms", false);
            } else if (iE >= 1000) {
                b(sb, iE / 1000, iE % 1000, 3, "us", false);
            } else {
                sb.append(iE);
                sb.append("ns");
            }
            i6 = i9;
        }
        if (z6 && i6 > 1) {
            sb.insert(1, '(').append(')');
        }
        return sb.toString();
    }
}
