import math


def qoe_and_cost_combined_reward(qoe_sum, transcoding_cost):
    """Computes QoE reward, taking the cost into account

    Parameters
    ----------
    qoe_sum : float
        The sum of Mean Opinion Scores for all working spectators
    transcoding_cost : float
        An arbitrary transcoding cost

    Returns
    -------
    reward : float
        A reward based on the QoE of all spectators and cost

    """
    if qoe_sum > transcoding_cost:
        reward = qoe_sum / transcoding_cost
    else:
        reward = -(1 + (qoe_sum / transcoding_cost))
    if reward == 0:
        return reward
    magnitude = int(math.log10(abs(reward)))
    if magnitude >= 1:
        reward /= math.pow(10, magnitude)
    return reward