download this file: func.math.php view text/plain: func.math.php file encoding: UTF-8 [goback]
<?php
##
## this file name is 'func.math.php'
##
## mathmatics functions
##
## [author]
##  - Chilbong Kim<san2(at)linuxchannel.net>
##
## [changes]
##  - 2003.09.05 : some add function
##  - 2003.04.05 : add alias function
##  - 2003.04.03 : new build
##
## [references]
##
## [usage]
##
## [example]
##

## get bin to bit
##
function get_bits($dec)
{      
  if(!
is_int($dec)) return 0;

  
$dec abs($dec);
  
$bits strrev(decbin($dec));
   
  return 
$bits// is not integer, is string
}

## this alias get_bits()
##
function get_bit($dec)
{
  return 
get_bits($dec);
}

## this alias get_bits()
##
function getbit($dec)
{
  return 
get_bits($dec);
}

## this alias get_bits()
##
function getbits($dec)
{
  return 
get_bits($dec);
}

## get uniq id(for SESSINID)
##
function get_uniqsid()
{
  return 
md5(uniqid(rand(),1));
}

## this alias get_uniqsid()
##
function get_uniqid()
{
  return 
get_uniqsid();
}

## this alias get_uniqsid()
##
function getuniqsid()
{
  return 
get_uniqsid();
}

## this alias get_uniqsid()
##
function getuniqid()
{
  return 
get_uniqsid();
}

## '%' operator
##
## Returns the floating point remainder (modulo)
## of the division of the arguments
##
function mod($x$y)
{
  if(
function_exists('fmod')) return fmod($x,$y); // PHP/4.2.x
  
return $x - (floor($x/$y) * $y); // float
}

function 
avg($array$values=array(), $size=0)
{
  
$values array_values($array);
  
$size sizeof($values);

  
//return sprintf('%.4f',array_sum($values)/$size);
  
return (float)(array_sum($values) / $size);
}

function 
std($array$avg=0)
{
  
$values = array();
  
$size $stdsum 0;
  
$avg avg($array,&$values,&$size);

  foreach(
$values AS $val$stdsum += pow($val-$avg,2);

  
//return sprintf('%.4f',sqrt($sum/($size-1))); // float
  
return (float)sqrt($stdsum/($size-1)); // float
}

?>