INNER CODE UNIT · Python

k

KwaiAppTeam/KOOM · koom-common/kwai-android-base/src/main/cpp/fmtlib/support/compute-powers.py:20

    k = significand_size + 1
    # Convert to binary and round.
    binary = '{:b}'.format(n)
    result.f = (int('{:0<{}}'.format(binary[:k], k), 2) + 1) / 2
    result.e = len(binary) - (exp_offset if exp < 0 else 0) - significand_size
    powers.append(result)
    # Sanity check.
    exp_offset10 = 400
    actual = result.f * 10 ** exp_offset10
    if result.e > 0:
        actual *= 2 ** result.e
    else:
        for j in range(-result.e):
            actual /= 2
    expected = 10 ** (exp_offset10 + exp)
    precision = len('{}'.format(expected)) - len('{}'.format(actual - expected))
    if precision < 19:
        print('low precision:', precision)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…