Added power function on arrays

This commit is contained in:
Dennis Eichhorn 2018-02-23 10:34:01 +01:00 committed by GitHub
parent a982bb432a
commit 3f438238e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -241,6 +241,50 @@ class Functions
{
return !((bool) ($a & 1));
}
/**
* Power all values in array.
*
* @param array $values Values to square
* @param float $exp Exponent
*
* @return array
*
* @since 1.0.0
* todo: move to utils?! implement sqrt for array as well... could be usefull for others (e.g. matrix)
*/
public static function powerFloat(array $values, float $exp = 2.0) : array
{
$squared = [];
foreach ($values as $value) {
$squared[] = $value * $exp;
}
return $squared;
}
/**
* Power all values in array.
*
* @param array $values Values to square
* @param int $exp Exponent
*
* @return array
*
* @since 1.0.0
* todo: move to utils?! implement sqrt for array as well... could be usefull for others (e.g. matrix)
*/
public static function powerInt(array $values, int $exp = 2) : array
{
$squared = [];
foreach ($values as $value) {
$squared[] = $value * $exp;
}
return $squared;
}
/**
* Gets the relative position on a circular construct.