forked from joomla/super-powers
update 2023-08-18 07:57:37
This commit is contained in:
parent
3d5c34a922
commit
b727169617
@ -13,7 +13,6 @@
|
|||||||
abstract MathHelper #Orange {
|
abstract MathHelper #Orange {
|
||||||
+ {static} bc(string $type, int $val1, ...) : string|int|null|bool
|
+ {static} bc(string $type, int $val1, ...) : string|int|null|bool
|
||||||
+ {static} sum(array $array, int $scale = 4) : float
|
+ {static} sum(array $array, int $scale = 4) : float
|
||||||
+ {static} sum(array $array, int $scale = 4) : float
|
|
||||||
}
|
}
|
||||||
|
|
||||||
note right of MathHelper::bc
|
note right of MathHelper::bc
|
||||||
@ -32,10 +31,6 @@ end note
|
|||||||
note right of MathHelper::sum
|
note right of MathHelper::sum
|
||||||
Basic sum of an array with more precision
|
Basic sum of an array with more precision
|
||||||
|
|
||||||
since: 3.0.9
|
|
||||||
return: float
|
|
||||||
Basic sum of an array with more precision
|
|
||||||
|
|
||||||
since: 3.0.9
|
since: 3.0.9
|
||||||
return: float
|
return: float
|
||||||
end note
|
end note
|
||||||
|
@ -98,33 +98,5 @@ abstract class MathHelper
|
|||||||
return array_sum($array);
|
return array_sum($array);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Basic sum of an array with more precision
|
|
||||||
*
|
|
||||||
* @param array $array The values to sum
|
|
||||||
* @param int $scale The scale value
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*
|
|
||||||
* @since 3.0.9
|
|
||||||
*/
|
|
||||||
public static function sum($array, $scale = 4)
|
|
||||||
{
|
|
||||||
// use the bcadd function if available
|
|
||||||
if (function_exists('bcadd'))
|
|
||||||
{
|
|
||||||
// set the start value
|
|
||||||
$value = 0.0;
|
|
||||||
// loop the values and run bcadd
|
|
||||||
foreach($array as $val)
|
|
||||||
{
|
|
||||||
$value = bcadd($value, (string) $val, $scale);
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
// fall back on array sum
|
|
||||||
return array_sum($array);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,31 +76,3 @@
|
|||||||
// fall back on array sum
|
// fall back on array sum
|
||||||
return array_sum($array);
|
return array_sum($array);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Basic sum of an array with more precision
|
|
||||||
*
|
|
||||||
* @param array $array The values to sum
|
|
||||||
* @param int $scale The scale value
|
|
||||||
*
|
|
||||||
* @return float
|
|
||||||
*
|
|
||||||
* @since 3.0.9
|
|
||||||
*/
|
|
||||||
public static function sum($array, $scale = 4)
|
|
||||||
{
|
|
||||||
// use the bcadd function if available
|
|
||||||
if (function_exists('bcadd'))
|
|
||||||
{
|
|
||||||
// set the start value
|
|
||||||
$value = 0.0;
|
|
||||||
// loop the values and run bcadd
|
|
||||||
foreach($array as $val)
|
|
||||||
{
|
|
||||||
$value = bcadd($value, (string) $val, $scale);
|
|
||||||
}
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
// fall back on array sum
|
|
||||||
return array_sum($array);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user