本文整理汇总了PHP中Math类的典型用法代码示例。如果您正苦于以下问题:PHP Math类的具体用法?PHP Math怎么用?PHP Math使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Math类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSub
public function testSub()
{
$math = new Math();
//Success
$this->assertEquals(3, $math->sub(8, 5));
//Success
$this->assertEquals(3, $math->sub(9, 6));
}
示例2: testMath
function testMath()
{
$math = new Math();
$coord1 = $math->GetGeoShortestDistance(40.6657, -80.3521, 32.7631, -96.7984);
$this->assertTrue(($coord1 == 1708.05), "Distance 1 received");
$coord2 = $math->GetGeoShortestDistance(50.95, 30.68, 50, 36.25);
$this->assertTrue(($coord2 == 407.83), "Distance 2 received");
}
示例3: cliParser
public static function cliParser($value)
{
try {
if (Validator::isValidCli($value)) {
$math = new Math();
$result = $math->runMath($value);
}
return iCalc::iHeaderMessage . iCalc::iMathMessage . "{$value[1]} {$value[2]} {$value[3]}" . iCalc::iRespMessage . "{$result}" . iCalc::iEndLineMessage;
} catch (CalculatorException $calcEx) {
$calcEx->getMessage(iCalc::iParserErrMessage);
}
}
示例4: indexTables
public function indexTables($a, $b, $hdr)
{
$this->ia->indexTable($a, $hdr);
$this->ib->indexTable($b, $hdr);
$this->hdr = $hdr;
$good = 0;
if (null == $this->ia->items) {
throw new HException('null iterable');
}
$__hx__it = $this->ia->items->keys();
while ($__hx__it->hasNext()) {
unset($key);
$key = $__hx__it->next();
$item_a = $this->ia->items->get($key);
$spot_a = $item_a->lst->length;
$item_b = $this->ib->items->get($key);
$spot_b = 0;
if ($item_b !== null) {
$spot_b = $item_b->lst->length;
}
if ($spot_a === 1 && $spot_b === 1) {
$good++;
}
unset($spot_b, $spot_a, $item_b, $item_a);
}
$this->quality = $good / Math::max(1.0, $a->get_height());
}
示例5: printWD
public static function printWD($wd)
{
if ($wd) {
return Math::wd_round($wd) . ' ' . Yii::app()->params['water_demand_unit'];
}
return '0 ' . Yii::app()->params['water_demand_unit'];
}
示例6: particularidade
public function particularidade($object)
{
//pr($object->Data);
$digAgConta = $object->Data['Agencia'] . $object->Data['Conta'];
$digAgContaCartNNum = $object->Data['Agencia'] . $object->Data['Conta'] . $object->Data['Carteira'] . $object->Data['NossoNumero'];
$object->Data['DigitoAgContaCarteiraNNum'] = Math::Mod10($digAgContaCartNNum);
$object->Data['DigitoAgConta'] = Math::Mod10($digAgConta);
}
示例7: max
static function max($a, $b)
{
if (!Math::isNaN($b)) {
return max($a, $b);
} else {
return Math::$NaN;
}
}
示例8: testBcMath
/**
* @requires extension bcmath
* @runInSeparateProcess
*/
public function testBcMath()
{
if (!extension_loaded('bcmath')) {
$this->markTestSkipped('The Bcmath extension is NOT loaded! You must enable it to run this test');
} elseif (extension_loaded('gmp')) {
$this->markTestSkipped('The GMP extension is loaded! You must remove it to run this test');
}
Math::add("3324234234234234234", "3324234234234234234");
$this->assertEquals(new BcEngine(), Math::getEngine());
}
示例9: testError
public function testError()
{
$math = new Math();
// no input
try {
$math->add();
} catch (\Exception $e) {
$this->assertEquals('Please provide numbers to add', $e->getMessage());
}
// no input
try {
$math->subtract();
} catch (\Exception $e) {
$this->assertEquals('Please provide numbers to subtract', $e->getMessage());
}
// no input
try {
$math->multiply();
} catch (\Exception $e) {
$this->assertEquals('Please provide numbers to multiply', $e->getMessage());
}
// no input
try {
$math->divide();
} catch (\Exception $e) {
$this->assertEquals('Please provide numbers to divide', $e->getMessage());
}
//invalid input
try {
$math->setA('adf');
} catch (\Exception $e) {
$this->assertEquals('Invalid input', $e->getMessage());
}
}
示例10: store
public function store()
{
$validator = Validator::make(Input::all(), ['paste' => 'required']);
if ($validator->fails()) {
return Redirect::route('create')->withErrors($validator);
}
try {
$paste = Paste::create(['paste' => Input::get('paste'), 'fork_of' => Input::get('fork', null)]);
} catch (Exception $e) {
return Redirect::route('create')->withErrors($e->getMessage());
}
return Redirect::route('show', Math::to_base($paste->id));
}
示例11: base26
public function base26($num)
{
$alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ($num < 0) {
return "-";
}
$out = "";
do {
$out = _hx_string_or_null($out) . _hx_string_or_null(_hx_char_at($alpha, _hx_mod($num, 26)));
$num = Math::floor($num / 26) - 1;
} while ($num >= 0);
return $out;
}
示例12: validate
protected function validate()
{
$start = Math::getNormalizedPosition($this->account, $this->start);
$end = Math::getNormalizedPosition($this->account, $this->end);
$length = abs($end - $start) + 1;
$this->position = $start;
$stepping = $end - $start < 0 ? -1 : +1;
for ($this->i = 0; $this->i < $length; $this->i++) {
$this->number = (int) $this->account[$this->position];
$this->iterationStep();
$this->position += $stepping;
}
}
示例13: __construct
public function __construct($baseURL, $number_of_results, $results_per_page)
{
if (!php_Boot::$skip_constructor) {
if ($results_per_page <= 0) {
throw new HException(new system_base_General_error(" results per page must be 1 or larger", 500, _hx_anonymous(array("fileName" => "Paginator.hx", "lineNumber" => 37, "className" => "system.base.Paginator", "methodName" => "new"))));
}
$full_pages = Math::floor($number_of_results / $results_per_page);
$spill_pages = system_base_Paginator_0($this, $baseURL, $full_pages, $number_of_results, $results_per_page);
$this->current_links = null;
$this->base_url = $baseURL;
$this->total_pages = $full_pages + $spill_pages;
}
}
示例14: divide
public static function divide(Number $num, Number $denum, $real = false)
{
if ($real) {
if ($denum->result == 0) {
throw new Exception('denum is zero');
}
$shots = floor($num->result / $denum->result);
$rest = Math::rest($num->result, $denum->result);
return new Number($shots, $rest);
} else {
$shots = $num->result / $denum->result;
return new Number($shots);
}
}
示例15: toString
public function toString()
{
$html = "";
$width = Math::floor(100 / $this->iframes->length) - 1;
$_g = 0;
$_g1 = $this->iframes;
while ($_g < $_g1->length) {
$iframeUrl = $_g1[$_g];
++$_g;
$html .= "\n\t" . "<iframe src=\"" . _hx_string_or_null($iframeUrl) . "\" style=\"width:" . Std::string($width) . "%; height:100%; margin:0px; padding:0px; border:1px solid;\"></iframe>";
unset($iframeUrl);
}
return ltrim($html);
}