import logging


def _compare_relative_difference(value: float, expected_value: float,
                                 threshold: float) -> bool:
  """Compares relative difference between value and expected_value against threshold.

  Args:
    value: a float value to be compared to expected value.
    expected_value: a float value that is expected.
    threshold: a float between 0 and 1.

  Returns:
    a boolean indicating whether the relative difference is within the
    threshold.
  """
  if value != expected_value:
    if expected_value:
      relative_diff = abs(value - expected_value) / abs(expected_value)
      if not (expected_value and relative_diff <= threshold):
        logging.warning('Relative difference %f exceeded threshold %f',
                        relative_diff, threshold)
        return False
  return True