import math


def _TValue(mean1, mean2, v1, v2, n1, n2):
  """Calculates a t-statistic value using the formula for Welch's t-test.

  The t value can be thought of as a signal-to-noise ratio; a higher t-value
  tells you that the groups are more different.

  Args:
    mean1: Mean of sample 1.
    mean2: Mean of sample 2.
    v1: Variance of sample 1.
    v2: Variance of sample 2.
    n1: Sample size of sample 1.
    n2: Sample size of sample 2.

  Returns:
    A t value, which may be negative or positive.
  """
  # If variance of both segments is zero, return some large t-value.
  if v1 == 0 and v2 == 0:
    return 1000.0
  return (mean1 - mean2) / (math.sqrt(v1 / n1 + v2 / n2))