37 public static function _add($left_operand, $right_operand, $scale = 50)
39 if (function_exists(
"bcadd"))
45 $res = $left_operand + $right_operand;
46 if (is_numeric($scale))
$res = round(
$res, $scale);
54 public static function _comp($left_operand, $right_operand, $scale = 50)
56 if (function_exists(
"bccomp"))
62 if (is_numeric($scale))
64 $left_operand = round($left_operand, $scale);
65 $right_operand = round($right_operand, $scale);
67 if ($left_operand == $right_operand)
return 0;
68 if ($left_operand > $right_operand)
return 1;
76 public static function _div($left_operand, $right_operand, $scale = 50)
78 if (function_exists(
"bcdiv"))
84 if ($right_operand == 0)
return NULL;
85 $res = $left_operand / $right_operand;
86 if (is_numeric($scale))
$res = round(
$res, $scale);
94 public static function _mod($left_operand, $modulus)
96 if (function_exists(
"bcmod"))
102 return $left_operand % $right_operand;
109 public static function _mul($left_operand, $right_operand, $scale = 50)
111 if (function_exists(
"bcmul"))
117 $res = $left_operand * $right_operand;
118 if (is_numeric($scale))
$res = round(
$res, $scale);
126 public static function _pow($left_operand, $right_operand, $scale = 50)
128 if (function_exists(
"bcpow"))
134 $res = pow($left_operand, $right_operand);
135 if (is_numeric($scale))
$res = round(
$res, $scale);
143 public static function _sqrt($operand, $scale = 50)
145 if (function_exists(
"bcsqrt"))
151 $res = sqrt($operand);
152 if (is_numeric($scale))
$res = round(
$res, $scale);
160 public static function _sub($left_operand, $right_operand, $scale = 50)
162 if (function_exists(
"bcsub"))
168 $res = $left_operand - $right_operand;
169 if (is_numeric($scale))
$res = round(
$res, $scale);
182 $float_str = (string)((
float)($float_str));
185 if(($pos = strpos(strtolower($float_str),
'e')) !==
false)
188 $exp = substr($float_str, $pos+1);
189 $num = substr($float_str, 0, $pos);
192 if((($num_sign = $num[0]) ===
'+') || ($num_sign ===
'-')) $num = substr($num, 1);
194 if($num_sign ===
'+') $num_sign =
'';
197 if((($exp_sign = $exp[0]) ===
'+') || ($exp_sign ===
'-')) $exp = substr($exp, 1);
198 else trigger_error(
"Could not convert exponential notation to decimal notation: invalid float string '$float_str'", E_USER_ERROR);
201 $right_dec_places = (($dec_pos = strpos($num,
'.')) ===
false) ? 0 : strlen(substr($num, $dec_pos+1));
203 $left_dec_places = ($dec_pos ===
false) ? strlen($num) : strlen(substr($num, 0, $dec_pos));
206 if($exp_sign ===
'+') $num_zeros = $exp - $right_dec_places;
207 else $num_zeros = $exp - $left_dec_places;
210 $zeros = str_pad(
'', $num_zeros,
'0');
213 if($dec_pos !==
false) $num = str_replace(
'.',
'', $num);
216 if($exp_sign ===
'+')
return $num_sign.$num.$zeros;
218 else return $num_sign.
'0.'.$zeros.$num;
221 else return $float_str;