本文整理汇总了C++中BigInteger::isZero方法的典型用法代码示例。如果您正苦于以下问题:C++ BigInteger::isZero方法的具体用法?C++ BigInteger::isZero怎么用?C++ BigInteger::isZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigInteger
的用法示例。
在下文中一共展示了BigInteger::isZero方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: extendedEuclidean
void extendedEuclidean(BigInteger m, BigInteger n,
BigInteger &g, BigInteger &r, BigInteger &s) {
if (&g == &r || &g == &s || &r == &s)
throw "BigInteger extendedEuclidean: Outputs are aliased";
BigInteger r1(1), s1(0), r2(0), s2(1), q;
/* Invariants:
* r1*m(orig) + s1*n(orig) == m(current)
* r2*m(orig) + s2*n(orig) == n(current) */
for (;;) {
if (n.isZero()) {
r = r1; s = s1; g = m;
return;
}
// Subtract q times the second invariant from the first invariant.
m.divideWithRemainder(n, q);
r1 -= q*r2; s1 -= q*s2;
if (m.isZero()) {
r = r2; s = s2; g = n;
return;
}
// Subtract q times the first invariant from the second invariant.
n.divideWithRemainder(m, q);
r2 -= q*r1; s2 -= q*s1;
}
}
示例2: gcd
friend BigInteger gcd(BigInteger a, BigInteger b) {
int powerOf2 = 0;
a.sign = 1;
b.sign = 1;
while(!b.isZero() && !a.isZero()) {
while(a.isEven() && b.isEven()) {
a /= 2;
b /= 2;
++powerOf2;
}
while(a.isEven()) {
a /= 2;
}
while(b.isEven()) {
b /= 2;
}
a -= b;
if(a.sign != 1){
a.sign = 1;
std::swap(a, b);
}
}
return pow(BigInteger(2), powerOf2) * (a.isZero() ? b : a);
}
示例3: open
String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
double /* sampleRate */, int /* bufferSizeSamples */) override
{
if (client == nullptr)
{
lastError = "No JACK client running";
return lastError;
}
lastError.clear();
close();
xruns = 0;
juce::jack_set_process_callback (client, processCallback, this);
juce::jack_set_port_connect_callback (client, portConnectCallback, this);
juce::jack_on_shutdown (client, shutdownCallback, this);
juce::jack_set_xrun_callback (client, xrunCallback, this);
juce::jack_activate (client);
deviceIsOpen = true;
if (! inputChannels.isZero())
{
for (JackPortIterator i (client, true); i.next();)
{
if (inputChannels [i.index] && i.clientName == getName())
{
int error = juce::jack_connect (client, i.ports[i.index], juce::jack_port_name ((jack_port_t*) inputPorts[i.index]));
if (error != 0)
JUCE_JACK_LOG ("Cannot connect input port " + String (i.index) + " (" + i.name + "), error " + String (error));
}
}
}
if (! outputChannels.isZero())
{
for (JackPortIterator i (client, false); i.next();)
{
if (outputChannels [i.index] && i.clientName == getName())
{
int error = juce::jack_connect (client, juce::jack_port_name ((jack_port_t*) outputPorts[i.index]), i.ports[i.index]);
if (error != 0)
JUCE_JACK_LOG ("Cannot connect output port " + String (i.index) + " (" + i.name + "), error " + String (error));
}
}
}
updateActivePorts();
return lastError;
}
示例4: applyToValue
bool RSAKey::applyToValue (BigInteger& value) const
{
if (part1.isZero() || part2.isZero() || value <= 0)
{
jassertfalse; // using an uninitialised key
value.clear();
return false;
}
BigInteger result;
while (! value.isZero())
{
result *= part2;
BigInteger remainder;
value.divideBy (part2, remainder);
remainder.exponentModulo (part1, part2);
result += remainder;
}
value.swapWith (result);
return true;
}
示例5: one
void
ExponentiationAlgorithm::compute(BigInteger& x, BigInteger& e, BigInteger& y, BigInteger m)
{
BigInteger one(1);
BigInteger two(2);
if ((e % two) == one) {
// std::cout << "TRACE - odd " << x << " " << e << " " << y << " " << m << std::endl;
// std::cout << "TRACE - check zero " << x .sign() << " " << y.sign() << std::endl;
// std::cout << "TRACE - (x * y) " << (x * y) << std::endl;
y = (x * y);
// std::cout << "TRACE - y " << y << std::endl;
e = e - one;
// std::cout << "TRACE - odd " << x << " " << e << " " << y << " " << m << std::endl;
} else {
// std::cout << "TRACE - even " << x << " " << e << " " << y << " " << m << std::endl;
x = (x * x);
e = (e / two);
// std::cout << "TRACE - even " << x << " " << e << " " << y << " " << m << std::endl;
}
if (!m.isZero()) {
// std::cout << "TRACE - !m.isZero " << x << " " << e << " " << y << " " << m << std::endl;
y = y % m;
x = x % m;
// std::cout << "TRACE - !m.isZero " << x << " " << e << " " << y << " " << m << std::endl;
}
}// compute
示例6: y
BigInteger
ExponentiationAlgorithm::pow(BigInteger x, BigInteger e)
{
BigInteger y(1);
while (!e.isZero()) {
compute(x, e, y, 0);
}
return y;
}// pow
示例7: multiplyPoint
ECPoint ECCurve::multiplyPoint(BigInteger &k, ECPoint &p)
{
BigInteger m = k;
ECPointJacobian q = toJacobian(p);
m = m % _q;
ECPointJacobian r;
while (!m.isZero()) {
if (m.lsb()) {
r = addJacobian(r, q);
}
m = m.rshift(1);
q = doubleJacobian(q);
}
return toAffine(r);
}
示例8: decryptXML
//==============================================================================
static XmlElement decryptXML (String hexData, RSAKey rsaPublicKey)
{
BigInteger val;
val.parseString (hexData, 16);
RSAKey key (rsaPublicKey);
jassert (key.isValid());
ScopedPointer<XmlElement> xml;
if (! val.isZero())
{
key.applyToValue (val);
const MemoryBlock mb (val.toMemoryBlock());
if (CharPointer_UTF8::isValidString (static_cast<const char*> (mb.getData()), (int) mb.getSize()))
xml = XmlDocument::parse (mb.toString());
}
return xml != nullptr ? *xml : XmlElement("key");
}
示例9: while
void CBC_PDF417HighLevelEncoder::encodeNumeric(CFX_WideString msg,
int32_t startpos,
int32_t count,
CFX_WideString& sb) {
int32_t idx = 0;
BigInteger num900 = 900;
while (idx < count) {
CFX_WideString tmp;
int32_t len = 44 < count - idx ? 44 : count - idx;
CFX_ByteString part =
((FX_WCHAR)'1' + msg.Mid(startpos + idx, len)).UTF8Encode();
BigInteger bigint = stringToBigInteger(part.c_str());
do {
int32_t c = (bigint % num900).toInt();
tmp += (FX_WCHAR)(c);
bigint = bigint / num900;
} while (!bigint.isZero());
for (int32_t i = tmp.GetLength() - 1; i >= 0; i--) {
sb += tmp.GetAt(i);
}
idx += len;
}
}
示例10: bigSieve
void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
const BigInteger& smallSieve, const int smallSieveSize)
{
jassert (! base[0]); // must be even!
result.setBit (numBits);
result.clearBit (numBits); // to enlarge the array
int index = smallSieve.findNextClearBit (0);
do
{
const int prime = (index << 1) + 1;
BigInteger r (base), remainder;
r.divideBy (prime, remainder);
int i = prime - remainder.getBitRangeAsInt (0, 32);
if (r.isZero())
i += prime;
if ((i & 1) == 0)
i += prime;
i = (i - 1) >> 1;
while (i < numBits)
{
result.setBit (i);
i += prime;
}
index = smallSieve.findNextClearBit (index + 1);
}
while (index < smallSieveSize);
}
示例11: open
String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
double /* sampleRate */, int /* bufferSizeSamples */)
{
if (client == nullptr)
{
lastError = "No JACK client running";
return lastError;
}
lastError = String::empty;
close();
juce::jack_set_process_callback (client, processCallback, this);
juce::jack_set_port_connect_callback (client, portConnectCallback, this);
juce::jack_on_shutdown (client, shutdownCallback, this);
juce::jack_activate (client);
isOpen_ = true;
if (! inputChannels.isZero())
{
if (const char** const ports = getJackPorts (client, true))
{
const int numInputChannels = inputChannels.getHighestBit() + 1;
for (int i = 0; i < numInputChannels; ++i)
{
const String portName (ports[i]);
if (inputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
{
int error = juce::jack_connect (client, ports[i], juce::jack_port_name ((jack_port_t*) inputPorts[i]));
if (error != 0)
jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
}
}
free (ports);
}
}
if (! outputChannels.isZero())
{
if (const char** const ports = getJackPorts (client, false))
{
const int numOutputChannels = outputChannels.getHighestBit() + 1;
for (int i = 0; i < numOutputChannels; ++i)
{
const String portName (ports[i]);
if (outputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
{
int error = juce::jack_connect (client, juce::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
if (error != 0)
jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
}
}
free (ports);
}
}
return lastError;
}