def calculate_mant_exp(value, precision=8):
    """
    This function calculates the exponent and mantissa from a desired value. Can e.g. be used for weights.
    :param value: the value for which you want to calculate mantissa and exponent
    :param precision: the allowed precision in bits for the mantissa
    :return: mantissa, exponent
    """
    des_value = value
    exponent = 0
    while abs(value) > 2 ** precision:
        value /= 2
        exponent += 1
    if not int(value) * 2 ** exponent == des_value:
        print('desired value of normalized max weight:', des_value)
        print('actual value:', int(value) * 2 ** exponent, 'mantissa:', int(value), 'exponent:', exponent)
    return int(value), exponent