private static function computeSquareIndex(
        string $exponent_remaining,
        int $actual_index,
        int $exp_scale,
        int $inner_scale
    ): array
    {
        $actual_rt = \bcpow('0.5', (string)$actual_index, $exp_scale);
        $r = \bcsub($exponent_remaining, $actual_rt, $inner_scale);

        while (\bccomp($r, '0', $exp_scale) === -1) {
            ++$actual_index;
            $actual_rt = \bcmul('0.5', $actual_rt, $inner_scale);
            $r = \bcsub($exponent_remaining, $actual_rt, $inner_scale);
        }

        return [$actual_index, $r];
    }