calc/算术

此包最新版本(1.0.2)没有可用的许可证信息。

计算算术函数的包:最大公约数、最小公倍数、平均值、加权平均值、因数和质因数

1.0.2 2018-05-09 11:38 UTC

This package is not auto-updated.

Last update: 2024-09-29 21:28:50 UTC


README

PHP的强大现代数学库

计算器是您将数学函数集成到应用程序中所需的唯一库。它是一个纯PHP自包含库,没有外部依赖。

它正在积极开发中,有开发版本(0.y.z)发布。

License

先决条件

用法

<?php
use Calc\Arithmetic\ArithmeticFunctions;

echo ArithmeticFunctions::lcm(3, 4); //12
echo "<br/>";
echo ArithmeticFunctions::lcmm([3, 4, 60]); //60
echo "<br/>";
echo ArithmeticFunctions::gcd(8, 12); // 4
echo "<br/>";
echo ArithmeticFunctions::gcd(8, 0); // 8
echo "<br/>";
echo ArithmeticFunctions::gcdm(array(42, 56, 28)); // 14
echo "<br/>";
echo ArithmeticFunctions::average(array(42, 56)); // 49
echo "<br/>";
echo ArithmeticFunctions::average(array(42, 56, 28)); // 42
echo "<br/>";
print_r(ArithmeticFunctions::factors(42)); // ( [0] => 1 [1] => 2 [2] => 3 [3] => 6 [4] => 7 [5] => 14 [6] => 21 [7] => 42 )
echo "<br/>";
print_r(ArithmeticFunctions::factors(2)); //  ( [0] => 1 [1] => 2 )
echo "<br/>";
print_r(ArithmeticFunctions::factors(0)); //  ( [0] => 0 )
echo "<br/>";
print_r(ArithmeticFunctions::primeFactors(42)); // ( [0] => 2 [1] => 3 [2] => 7 )
echo "<br/>";
print_r(ArithmeticFunctions::primeFactors(39)); //  ( [0] => 3 [1] => 13 )
echo "<br/>";
print_r(ArithmeticFunctions::primeFactors(0)); //  (  )
echo "<br/>";
print(ArithmeticFunctions::weightedAverage(array(
    35 => 1000,
    15 => 2000,
    30 => 100,
    10 => 90,
    5 => 100,
    5 => 3120
))); //  889.47
echo "<br/>";
print(ArithmeticFunctions::weightedAvegare(array(
    2 => 42,
    3 => 56,
    9 => 28,
))); //  36

获取库

$ composer require calc/arithmetic