/** * HARMEAN * * Returns the harmonic mean of a data set. The harmonic mean is the reciprocal of the * arithmetic mean of reciprocals. * * @param array of mixed Data Series * @return float */ public static function HARMEAN() { // Return value $returnValue = self::NA(); // Loop through arguments $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args()); if (PHPExcel_Calculation_Functions::MIN($aArgs) < 0) { return self::$_errorCodes['num']; } $aCount = 0; foreach ($aArgs as $arg) { // Is it a numeric value? if (is_numeric($arg) && !is_string($arg)) { if ($arg <= 0) { return self::$_errorCodes['num']; } if (is_null($returnValue)) { $returnValue = 1 / $arg; } else { $returnValue += 1 / $arg; } ++$aCount; } } // Return if ($aCount > 0) { return 1 / ($returnValue / $aCount); } else { return $returnValue; } }