def squash_to_unit_interval(x: float, constant: float) -> float:
  """Scales non-negative x to be in range [0, 1], with a squash."""
  if constant <= 0:
    raise ValueError('Squash constant must be greater than zero.')
  if x < 0:
    raise ValueError('Squash can only be performed on a positive value.')
  return x / (x + constant)