Ignore:
Timestamp:
Feb 20, 2015, 9:31:53 AM (9 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/old/stat_functions.php

    r51 r52  
    22
    33$ValueTypes = array('min', 'avg', 'max');
    4 $PrefixMultipliers = array(
    5   array('y', 'yocto', pow(10, -24)),
    6   array('z', 'zepto', pow(10, -21)),
    7   array('a', 'atto', pow(10, -18)),
    8   array('f', 'femto', pow(10, -15)),
    9   array('p', 'piko', pow(10, -12)),
    10   array('n', 'nano', pow(10, -9)),
    11   array('u', 'mikro', pow(10, -6)),
    12   array('m', 'mili', pow(10, -3)),
    13   array('', '', pow(10, 0)),
    14   array('k', 'kilo', pow(10, 3)),
    15   array('M', 'mega', pow(10, 6)),
    16   array('G', 'giga', pow(10, 9)),
    17   array('T', 'tera', pow(10, 12)),
    18   array('P', 'peta', pow(10, 15)),
    19   array('E', 'exa', pow(10, 18)),
    20   array('Z', 'zetta', pow(10, 21)),
    21   array('Y', 'yotta', pow(10, 24)),
    22 );
    23 
    24 function TruncateDigits($Value, $Digits = 4)
    25 {
    26   for($II = 2; $II > -6; $II--)
    27   {
    28     if($Value >= pow(10, $II))
    29     {
    30       if($Digits < ($II + 1)) $RealDigits = $II + 1;
    31         else $RealDigits = $Digits;
    32       $Value = round($Value / pow(10, $II - $RealDigits + 1)) * pow(10, $II - $RealDigits + 1);
    33       break;
    34     }
    35   }
    36   return($Value);
    37 }
    38 
    39 function AddPrefixMultipliers($Value, $Unit, $Digits = 4)
    40 {
    41   global $PrefixMultipliers;
    42 
    43   if($Unit == '') return(TruncateDigits($Value, $Digits));
    44   $I = 8;
    45   if($Value > 0) $II = 1;
    46   else if($Value < 0) $II = -1;
    47   else $II = 0;
    48   while((($Value / $PrefixMultipliers[$I + $II][2]) > $II) and (($I + $II) >= 0)
    49     and (($I + $II) <= count($PrefixMultipliers))) $I = $I + $II;
    50   $Value = $Value / $PrefixMultipliers[$I][2];
    51 
    52   // Truncate digits count
    53   $Value = TruncateDigits($Value, $Digits);
    54 
    55   return($Value.' '.$PrefixMultipliers[$I][0].$Unit);
    56 }
    574
    585function GetMicrotime()
Note: See TracChangeset for help on using the changeset viewer.