[go: up one dir, main page]

Menu

[r19]: / tags / 0.58 / lib / calc.php  Maximize  Restore  History

Download this file

121 lines (84 with data), 2.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/*********************************************************
// FILE: calc.inc.php
// DESCRIPTION: Contains functions that have that are for
// some sort of mathematical calculations
// or binary manipulation.
//
// CREATION
// DATE: 04-19-2006
//
// HISTORY:
//
*********************************************************/
function bitset_compare($bit1,$bit2,$admin) {
$auth = null;
if ( (int)$bit1 & (int)$bit2 ) $auth = 1;
if ($admin) {
if ( (int)$bit1 & (int)$admin ) $auth = 1;
}
if (!$auth) return false;
else return true;
}
/*********************************************************
*********************************************************/
function bitCal($limit) {
$num = 1;
for ($row=0;$row<$limit;$row++) {
if ($limit!=0) $num = $num * 2;
}
return $num;
}
/*********************************************************
*********************************************************/
function revBitCal($limit) {
$counter = "0";
while ($limit!="1") {
$counter++;
$limit = $limit/2;
}
return $counter;
}
/*********************************************************
*********************************************************/
function intPercent($num,$total) {
if ($total != 0) {
$percent = ($num/$total) * 100;
$temp = intval($percent) + ".5";
//round up if necessary
if ($percent >= $temp) {
$value = intval($percent) + 1;
}
else {
$value = intval($percent);
}
}
else $value = "0";
return $value;
}
/*********************************************************
*********************************************************/
function intValue($num) {
$temp = intval($num) + ".5";
//round up if necessary
if ($num >= $temp) {
$value = intval($num) + 1;
}
else {
$value = intval($num);
}
return $value;
}
/*********************************************************
*********************************************************/
function floatValue($num,$count) {
$pos = strpos($num,".") + 1 + $count;
$floatNum = substr($num,0,$pos);
$checkDigit = substr($num,strlen($floatNum),1);
$changeDigit = substr($floatNum,strlen($floatNum)-1,1);
//round up if necessary
if ($checkDigit>=5) $last = $changeDigit + 1;
else $last = $changeDigit;
$value = substr($floatNum,0,strlen($floatNum)-1).$last;
return $value;
}