/** * @dataProvider getAdapters */ public function testStrictIntegerReturnValues(MathAdapterInterface $math) { $x = 10; $y = 4; $mod = $math->mod($x, $y); $this->assertTrue(is_string($mod) && !is_resource($mod)); $add = $math->add($x, $y); $this->assertTrue(is_string($add) && !is_resource($add)); $sub = $math->sub($add, $y); $this->assertTrue(is_string($sub) && !is_resource($sub)); $mul = $math->mul($x, $y); $this->assertTrue(is_string($mul) && !is_resource($mul)); $div = $math->div($mul, $y); $this->assertTrue(is_string($div) && !is_resource($div)); $pow = $math->pow($x, $y); $this->assertTrue(is_string($pow) && !is_resource($div)); $powmod = $math->powmod($x, $y, $y); $this->assertTrue(is_string($powmod) && !is_resource($powmod)); $bitwiseand = $math->bitwiseAnd($x, $y); $this->assertTrue(is_string($bitwiseand) && !is_resource($bitwiseand)); $hexdec = $math->decHex($x); $this->assertTrue(is_string($hexdec) && !is_resource($hexdec)); $dechex = $math->hexDec($hexdec); $this->assertTrue(is_string($dechex) && !is_resource($dechex)); }
/** * @param $a * @param $b * @param $cond */ public function cswapValue(&$a, &$b, $cond) { $size = max(strlen($this->adapter->baseConvert($a, 10, 2)), strlen($this->adapter->baseConvert($b, 10, 2))); $mask = 1 - intval($cond); $mask = str_pad('', $size, $mask, STR_PAD_LEFT); $mask = $this->adapter->baseConvert($mask, 2, 10); $tA = $this->adapter->bitwiseAnd($a, $mask); $tB = $this->adapter->bitwiseAnd($b, $mask); $a = $this->adapter->bitwiseXor($this->adapter->bitwiseXor($a, $b), $tB); $b = $this->adapter->bitwiseXor($this->adapter->bitwiseXor($a, $b), $tA); $a = $this->adapter->bitwiseXor($this->adapter->bitwiseXor($a, $b), $tB); }