Exemple #1
0
 /**
  * This method evaluates whether the left operand is NOT equal to the right operand.
  *
  * @access public
  * @static
  * @param IInt32\Type $x                                    the left operand
  * @param Core\Type $y                                      the right operand
  * @return IBool\Type                                       whether the left operand is NOT equal
  *                                                          to the right operand
  */
 public static function ne(IInt32\Type $x, Core\Type $y) : IBool\Type
 {
     // !=
     return IBool\Module::not(IInt32\Module::eq($x, $y));
 }
Exemple #2
0
 /**
  * This method returns the item at the specified index.
  *
  * @access public
  * @final
  * @param IInt32\Type $i                                    the index of the item
  * @return mixed                                            the item at the specified index
  */
 public final function item(IInt32\Type $i)
 {
     $j = IInt32\Type::zero();
     for ($zs = $this; !$zs->__isEmpty(); $zs = $zs->tail()) {
         if (IInt32\Module::eq($i, $j)->unbox()) {
             return $zs->head();
         }
         $j = IInt32\Module::increment($j);
     }
     throw new Throwable\OutOfBounds\Exception('Unable to return item at index :index.', array(':index' => $i->unbox()));
 }
 /**
  * This method tests the "eq" method.
  *
  * @dataProvider data_eq
  */
 public function test_eq(array $provided, array $expected)
 {
     $p0 = IInt32\Module::eq(IInt32\Type::box($provided[0]), IInt32\Type::box($provided[1]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Exemple #4
0
 /**
  * This method evaluates whether the left operand is identical to the right operand.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the left operand
  * @param Core\Type $ys                                     the right operand
  * @return IBool\Type                                       whether the left operand is identical
  *                                                          to the right operand
  */
 public static function id(IHashMap\Type $xs, Core\Type $ys) : IBool\Type
 {
     // ===
     if ($ys !== null && $xs->__typeOf() === $ys->__typeOf()) {
         if (IInt32\Module::eq($xs->size(), $ys->size())) {
             return IBool\Type::box((string) serialize($xs) == (string) serialize($ys));
         }
     }
     return IBool\Type::false();
 }
Exemple #5
0
 /**
  * This method returns a value as a boxed object.  A value is typically a PHP typed
  * primitive or object.  It is considered type-safe.
  *
  * @access public
  * @static
  * @param mixed $value                                      the value(s) to be boxed
  * @return IRatio\Type                                      the boxed object
  */
 public static function make($value) : IRatio\Type
 {
     $values = is_array($value) ? $value : func_get_args();
     $values = array_map(function ($value) {
         return $value instanceof IInt32\Type ? $value : IInt32\Type::make($value);
     }, $values);
     $denominator = $values[1];
     $signum = IInt32\Module::signum($denominator)->unbox();
     if ($signum == 0) {
         throw new Throwable\InvalidArgument\Exception('Unable to create ratio. Denominator must not be zero.');
     }
     $numerator = $values[0];
     if (IInt32\Module::signum($numerator)->unbox() == 0) {
         return IRatio\Type::zero();
     }
     if ($signum < 0) {
         $numerator = IInt32\Module::negate($numerator);
         $denominator = IInt32\Module::negate($denominator);
     }
     $gcd = IInt32\Module::gcd($numerator, $denominator);
     if (!IInt32\Module::eq($gcd, IInt32\Type::one())->unbox()) {
         $numerator = IInt32\Module::divide($numerator, $gcd);
         $denominator = IInt32\Module::divide($denominator, $gcd);
     }
     return new IRatio\Type($numerator, $denominator);
 }
Exemple #6
0
 /**
  * This method returns whether the ratio is a whole number.
  *
  * @access public
  * @static
  * @param IRatio\Type $x                                    the ratio to be evaluated
  * @return IBool\Type                                       whether the ratio is a whole
  *                                                          number
  */
 public static function isInteger(IRatio\Type $x) : IBool\Type
 {
     return IBool\Module::or_(IInt32\Module::eq($x->numerator(), IInt32\Type::zero()), IInt32\Module::eq($x->denominator(), IInt32\Type::one()));
 }