code: public static function TINV($probability, $degrees)
      {
          $probability = Functions::flattenSingleValue($probability);
          $degrees = floor(Functions::flattenSingleValue($degrees));
  
          if ((is_numeric($probability)) && (is_numeric($degrees))) {
              $xLo = 100;
              $xHi = 0;
  
              $x = $xNew = 1;
              $dx = 1;
              $i = 0;
  
              while ((abs($dx) > Functions::PRECISION) && ($i++ < self::MAX_ITERATIONS)) {
                  // Apply Newton-Raphson step
                  $result = self::TDIST($x, $degrees, 2);
                  $error = $result - $probability;
                  if ($error == 0.0) {
                      $dx = 0;
                  } elseif ($error < 0.0) {
                      $xLo = $x;
                  } else {
                      $xHi = $x;
                  }
                  // Avoid division by zero
                  if ($result != 0.0) {
                      $dx = $error / $result;
                      $xNew = $x - $dx;
                  }
                  // If the NR fails to converge (which for example may be the
                  // case if the initial guess is too rough) we apply a bisection
                  // step to determine a more narrow interval around the root.
                  if (($xNew < $xLo) || ($xNew > $xHi) || ($result == 0.0)) {
                      $xNew = ($xLo + $xHi) / 2;
                      $dx = $xNew - $x;
                  }
                  $x = $xNew;
              }
              if ($i == self::MAX_ITERATIONS) {
                  return Functions::NA();
              }
  
              return round($x, 12);
          }
  
          return Functions::VALUE();
      }
docs: TINV.
  
  Returns the one-tailed probability of the chi-squared distribution.
  
  @param float $probability Probability for the function
  @param float $degrees degrees of freedom
  
  @return float