Exemple #1
0
 public function isEquals(Number $n)
 {
     if ($this->getValue() == $n->getValue() && $this->isExtra() == $n->isExtra()) {
         return true;
     }
     return false;
 }
Exemple #2
0
 public function multiply(Number $precision, $scale = null)
 {
     $scale = $this->scale($scale);
     $result = bcmul($this->value, $precision->getValue(), self::MAX_PRECISION);
     $diff = $this->round($result, $scale);
     return new self($diff, $scale);
 }
Exemple #3
0
 /**
  * {@inheritDoc}
  */
 public function lessThan(Number $n)
 {
     return $this->value <= $n->getValue();
 }
Exemple #4
0
 /**
  * @param $name
  * @param $args
  * @return String
  */
 protected function bcCalc($name, $args)
 {
     $value = current($args);
     if ($value instanceof number\Percentage) {
         switch ($name) {
             case 'bcmul':
             case 'bcdiv':
                 $value->bcdiv(100)->bcmul($this->getValue());
                 break;
             default:
                 $value = $value->of($this);
                 break;
         }
     } elseif (!$value instanceof Number) {
         if (is_numeric($value)) {
             $value = new Number($value);
         } else {
             trigger_error('BC Functions must be compared with another Number or a valid number');
         }
     }
     if ($name == 'bcdiv' && $value->getValue() == 0) {
         $result = 0;
     } else {
         $result = $name($this->getValue(), $value->getValue(), $this->getPrecision());
     }
     return $result;
 }
 /**
  * @dataProvider providerValueIsCastedToFloatInConstructor
  */
 public function testValueIsCastedToFloatInConstructor($expectedValue, Number $number)
 {
     $this->assertInternalType('float', $number->getValue());
     $this->assertSame($expectedValue, $number->getValue());
 }
Exemple #6
0
<?php

require_once 'Number.php';
if (isset($_POST['num'])) {
    if (isset($_POST['dowhat'])) {
        $num = new Number(intval($_POST['num']));
        switch ($_POST['dowhat']) {
            case 'nth':
                $nthPrime = $num->getNthPrime();
                $enders = array('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th');
                if ($num->getValue() % 100 >= 11 && $num->getValue() % 100 <= 13) {
                    $abbreviation = 'th';
                } else {
                    $abbreviation = $enders[$num->getValue() % 10];
                }
                echo "The " . $num->getValue() . $abbreviation . " prime number is " . $nthPrime;
                break;
            case 'allPrimes':
                if ($num->getPrimesBelowN()) {
                    $handle = fopen('sieveResults.txt', 'r') or die("Couldn't do it captain!");
                    if ($handle) {
                        while (!feof($handle)) {
                            $buffer = fgets($handle, 4096);
                            echo $buffer;
                        }
                    }
                    fclose($handle);
                }
                break;
            case 'isPrime':
                echo $num->isPrime();