/** * This method compares the operands for order. * * @access public * @static * @param IUnit\Type $x the left operand * @param IUnit\Type $y the right operand * @return ITrit\Type the order as to whether the left * operand is less than, equals to, * or greater than the right operand */ public static function compare(IUnit\Type $x, IUnit\Type $y) : ITrit\Type { if (IUnit\Module::eq($x, $y)->unbox()) { return ITrit\Type::zero(); } return ITrit\Type::make(strcmp($x->__typeOf(), $y->__typeOf())); }
/** * This method compares the specified object with the current object for order. * * @access public * @static * @param IString\Type $xs the left operand * @param IString\Type $ys the object to be compared * @return ITrit\Type whether the current object is less than, * equal to, or greater than the specified * object */ public static function compare(IString\Type $xs, IString\Type $ys) : ITrit\Type { return ITrit\Type::make(strcmp($xs->unbox(), $ys->unbox())); }
/** * This method tests the "toString" method. * * @dataProvider data_toString */ public function test_toString(array $provided, array $expected) { $p0 = ITrit\Type::make($provided[0])->toString(); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0); $this->assertSame($e0, $p0->unbox()); }
/** * This method returns -1, 0 or 1 when the value is negative, zero, or positive. * * @access public * @static * @param IInt32\Type $x the number to be evaluated * @return ITrit\Type the result */ public static function signum(IInt32\Type $x) : ITrit\Type { return ITrit\Type::make($x->unbox()); }
/** * This method compares the specified object with the current object for order. * * @access public * @static * @param IHashMap\Type $xs the left operand * @param IHashMap\Type $ys the object to be compared * @return ITrit\Type whether the current object is less than, * equal to, or greater than the specified * object */ public static function compare(IHashMap\Type $xs, IHashMap\Type $ys) : ITrit\Type { $x_length = $xs->__size(); $y_length = $ys->__size(); if ($x_length == $y_length) { $xi = IHashMap\Module::iterator($xs); foreach ($xi as $k => $v) { if (!$ys->__hasKey($k) || !$ys->item($k)->__eq($v)) { return ITrit\Type::make(strcmp((string) serialize($xs), (string) serialize($ys))); // order is not "stable" } } return ITrit\Type::zero(); } else { if ($x_length < $y_length) { return ITrit\Type::negative(); } else { // ($x_length > $y_length) return ITrit\Type::positive(); } } }
/** * This method compares the operands for order. * * @access public * @static * @param IInteger\Type $x the left operand * @param IInteger\Type $y the right operand * @return ITrit\Type the order as to whether the left * operand is less than, equals to, * or greater than the right operand */ public static function compare(IInteger\Type $x, IInteger\Type $y) : ITrit\Type { return ITrit\Type::make(gmp_cmp($x->unbox(), $y->unbox())); }