public function testSub() { $math = new Math(); //Success $this->assertEquals(3, $math->sub(8, 5)); //Success $this->assertEquals(3, $math->sub(9, 6)); }
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"); }
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); } }
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()); }
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']; }
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); }
static function max($a, $b) { if (!Math::isNaN($b)) { return max($a, $b); } else { return Math::$NaN; } }
/** * @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()); }
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()); } }
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)); }
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; }
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; } }
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; } }
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); } }
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); }
public function index($value, $parameters = array()) { if (!isset($parameters[0])) { return 'Unknown'; } if (!preg_match(Pattern::COORDINATES, $value, $point_1_matches)) { return 'Unknown'; } if (!preg_match(Pattern::COORDINATES, $parameters[0], $point_2_matches)) { return 'Unknown'; } $point_1 = array($point_1_matches[1], $point_1_matches[2]); $point_2 = array($point_2_matches[1], $point_2_matches[2]); return Math::getDistanceInKilometers($point_1, $point_2); }
static function do_hash($s) { $b = 378551; $a = 63689; $hash = 0; $i = 0; $_g1 = 0; $_g = strlen($s); while ($_g1 < $_g) { $i1 = $_g1++; $hash = $hash * $a + _hx_char_code_at($s, $i1); $a = $a * $b; unset($i1); } return Math::abs($hash); }
static function hex($n, $digits = null) { $s = dechex($n); $len = 8; if (strlen($s) > StringTools_0($digits, $len, $n, $s)) { $s = _hx_substr($s, -$len, null); } else { if ($digits !== null) { if (strlen("0") === 0 || strlen($s) >= $digits) { $s = $s; } else { $s = str_pad($s, Math::ceil(($digits - strlen($s)) / strlen("0")) * strlen("0") + strlen($s), "0", STR_PAD_LEFT); } } } return strtoupper($s); }
/** * 本地验证 * @param type $ssid * @param type $result * @return type */ public static function sendVerifyLocalRequest($ssid, $result) { $mass = Context::getInstance()->get('yuc_mass', ''); $code = Crypt::decrypt(urldecode($mass), Math::erypt_key()); $code = str_replace(",", "", $code); if ($code != '' && strtolower($code) === strtolower($result)) { self::$_yuc_result = 1; self::$_yuc_code = ''; self::$_yuc_details = '验证码输入正确'; } else { self::$_yuc_result = 0; self::$_yuc_code = 'E_LOCALVALID_001'; self::$_yuc_details = '验证码验证失败'; } Log::Write('本地验证完成,输入结果为:' . $result . ';' . '', Log::DEBUG); return array('code' => self::$_yuc_code, 'result' => self::$_yuc_result, 'details' => self::$_yuc_details); }
function getquota($who, $what) { global $conf; if ($what == 'user') { $quota = evoexec("-qu {$who}"); } elseif ($what == 'group') { if ($conf['domaines']['driver'] == 'file') { $quota = evoexec("-s"); } elseif ($conf['domaines']['driver'] == 'ldap') { $quota = evoexec("-qg {$who}"); } } list($now, $limit) = split("/", $quota); $now = $now / 1024; $limit = $limit / 1024; $quota = "<b>" . Math::arrondi($now) . "M</b>/" . Math::arrondi($limit) . "M"; return $quota; }
/** * particularidade() Faz em tempo de execução mudanças que sejam imprescindíveis * para a geração correta do código de barras * Especificamente para o Hsbc, temos duas particularidas: Data no formato juliano, e * um dígito verificador triplo para o nosso número. * * * @version 0.1 28/05/2011 Initial */ public function particularidade($object) { switch ($object->Vendedor->Carteira) { case '18-6': $object->Boleto->NossoNumero = $object->Data['CodigoCedente'] . Math::Mod11($object->Data['NossoNumero'], 0, 0, true); break; case '18-6-17': $this->layoutCodigoBarras = ':Banco:Moeda:FatorVencimento:Valor:CodigoCedente:NossoNumero21'; break; case '18-7': $this->layoutCodigoBarras = ':Banco:Moeda:FatorVencimento:Valor000000:CodigoCedente:NossoNumero:Carteira'; $object->Boleto->NossoNumero = $object->Data['CodigoCedente'] . $object->Data['NossoNumero']; break; case '18-8': $this->layoutCodigoBarras = ':Banco:Moeda:FatorVencimento:Valor000000:CodigoCedente:NossoNumero:Carteira'; $object->Boleto->NossoNumero = $object->Data['CodigoCedente'] . Math::Mod11($object->Data['NossoNumero'], 0, 0, true); break; } $object->Vendedor->Carteira = '18'; }
static function create() { $s = new _hx_array(array()); $_g = 0; while ($_g < 8) { $i = $_g++; $s[$i] = _hx_char_at("0123456789ABCDEF", Math::floor(Math::random() * 16)); unset($i); } $s[8] = "-"; $_g1 = 9; while ($_g1 < 13) { $i1 = $_g1++; $s[$i1] = _hx_char_at("0123456789ABCDEF", Math::floor(Math::random() * 16)); unset($i1); } $s[13] = "-"; $s[14] = "4"; $_g2 = 15; while ($_g2 < 18) { $i2 = $_g2++; $s[$i2] = _hx_char_at("0123456789ABCDEF", Math::floor(Math::random() * 16)); unset($i2); } $s[18] = "-"; $s[19] = "" . _hx_string_or_null(_hx_char_at("89AB", Math::floor(Math::random() * 4))); $_g3 = 20; while ($_g3 < 23) { $i3 = $_g3++; $s[$i3] = _hx_char_at("0123456789ABCDEF", Math::floor(Math::random() * 16)); unset($i3); } $s[23] = "-"; $_g4 = 24; while ($_g4 < 36) { $i4 = $_g4++; $s[$i4] = _hx_char_at("0123456789ABCDEF", Math::floor(Math::random() * 16)); unset($i4); } return $s->join(""); }
public function calculate( ) { $this->initializeCalculator( ); if( ! empty($_POST['hasSubmit']) ) { $leftOperand = (isset($_POST['leftOperand']) ? (int)$_POST['leftOperand'] : null ); $rightOperand = (isset($_POST['rightOperand']) ? (int)$_POST['rightOperand'] : null ); $firstOperator = (isset($_POST['firstOperator']) ? $_POST['firstOperator'] : null ); $secondOperator = (isset($_POST['secondOperator']) ? $_POST['secondOperator'] : null ); if( $secondOperator != '=' ) { $this->registry->template->firstOperator = $secondOperator; } $calculator = new Math( ); $calculator->setFirstOperand($leftOperand); $calculator->setSecondOperand($rightOperand); $calculator->setFirstOperator($firstOperator); $calculator->setSecondOperator($secondOperator); $this->registry->template->leftOperand = $calculator->calculate(); } $this->registry->template->show('math_index'); }
static function snapWeek($dt, $direction, $required) { $current = datetime__DateTime_DateTime_Impl_::getWeekDay($dt, null); $days = Math::ffloor(($dt - 62135596800.0) / 86400); switch ($direction) { case -1: $diff = null; if ($current >= $required) { $diff = $current - $required; } else { $diff = $current + 7 - $required; } return ($days - $diff) * 86400; break; case 1: $diff1 = null; if ($required > $current) { $diff1 = $required - $current; } else { $diff1 = $required + 7 - $current; } return ($days + $diff1) * 86400; break; case 0: $diff2 = null; if ($current >= $required) { $diff2 = $current - $required; } else { $diff2 = $current + 7 - $required; } $previous = ($days - $diff2) * 86400; $diff3 = null; if ($required > $current) { $diff3 = $required - $current; } else { $diff3 = $required + 7 - $current; } $next = ($days + $diff3) * 86400; if ($next - ($dt - 62135596800.0) > $dt - 62135596800.0 - $previous) { return $previous; } else { return $next; } break; } }
</thead> <tbody> <?php foreach ($geom->zones() as $zone) { ?> <tr> <td><?php echo CHtml::encode($zone->zoneDescription) . ' - ' . CHtml::encode($zone->zone_name); ?> </td> <td><?php echo CHtml::encode(Math::pe_round($zone->pe)); ?> </td> <td><?php echo CHtml::encode(Math::wd_round($zone->water_demand)) . ' ' . Yii::app()->params['water_demand_unit']; ?> </td> </tr> <?php } ?> </tbody> </table> </page> <?php } ?> </div> </page>
<?php $ret = array(); foreach ($model->zones() as $zone) { $z = array('wr_id' => $model->wr->id, 'geom_id' => $model->id, 'id' => $zone->id, 'zone' => $zone->zoneDescription, 'pe' => Math::pe_round($zone->pe), 'wd' => Math::wd_round($zone->water_demand) . ' ' . Yii::app()->params['water_demand_unit']); array_push($ret, $z); } echo htmlspecialchars(json_encode($ret), ENT_NOQUOTES);
<?php if (!defined('BASEPATH')) { exit('No direct script access allowed'); } include_once PATH_THIRD . 'math/addon.setup.php'; $plugin_info = array('pi_author' => MATH_AUTHOR, 'pi_author_url' => MATH_AUTHOR_URL, 'pi_description' => MATH_DESC, 'pi_name' => MATH_NAME, 'pi_version' => MATH_VER, 'pi_usage' => Math::usage()); class Math { public $return_data = ''; public function __construct() { // Get formula $formula = ee()->TMPL->fetch_param('formula'); $error = false; $result = ''; if ($formula !== false) { // Convert html entities to math characters $formula = html_entity_decode($formula); // Replace parameters $params = ee()->TMPL->fetch_param('params'); $numeric_error = ee()->TMPL->fetch_param('numeric_error', 'Invalid input'); if ($params !== false) { $params = explode('|', $params); $i = 1; foreach ($params as $param) { if (!is_numeric($param)) { $param = preg_replace('/[^0-9.]*/', '', $param); if (!is_numeric($param)) { $this->return_data = $numeric_error; return;
class Math { public function __construct() { } static $PI; static $NaN; static $POSITIVE_INFINITY; static $NEGATIVE_INFINITY; static function floor($v) { return (int) floor($v); } static function ceil($v) { return (int) ceil($v); } static function isFinite($f) { return is_finite($f); } function __toString() { return 'Math'; } } Math::$PI = M_PI; Math::$NaN = acos(1.01); Math::$NEGATIVE_INFINITY = log(0); Math::$POSITIVE_INFINITY = -Math::$NEGATIVE_INFINITY;
/** * Unpack a long. * * @param mixed $value * * @return int the long unpacked */ public static function unpackLong($value) { $first = substr($value, 0, 4); $last = substr($value, 4, 4); // First of all, unpack 8 bytes, divided into hi and low parts $hi = unpack('N', $first); $hi = reset($hi); $low = unpack('N', $last); $low = reset($low); // Unpack 64-bit signed long return Math::unpackI64($hi, $low); }
/** * @param CannonBall|Point $object * @return bool */ public function isHit($object) { if ($object instanceof CannonBall) { $index = 0; foreach ($object->pixels as $pixel) { $pixelPosition = new Point($object->position->x + $pixel->x, $object->position->y + $pixel->y); $am = Math::pointDiff($this->a, $pixelPosition); $dot_am_ab = Math::dotProduct($am, $this->ab); $dot_am_ac = Math::dotProduct($am, $this->ac); if (0 < $dot_am_ab && $dot_am_ab < $this->dot_ab && (0 < $dot_am_ac && $dot_am_ac < $this->dot_ac)) { unset($object->pixels[$index]); return $pixelPosition; } $index++; } return false; } $point_m = $object; $am = Math::pointDiff($this->a, $point_m); $dot_am_ab = Math::dotProduct($am, $this->ab); $dot_am_ac = Math::dotProduct($am, $this->ac); if (0 < $dot_am_ab && $dot_am_ab < $this->dot_ab && (0 < $dot_am_ac && $dot_am_ac < $this->dot_ac)) { return $point_m; } return false; }