ter transact_dividend( sttx const& txn, transactionengineparams params, transactionengine* engine) { return dividend (txn, params, engine).apply(); }
BigInt& BigInt::operator/=(const BigInt& that) { if (that.isZero()) throw std::invalid_argument("division by zero"); else if (positive && *this < that) return *this = zero; bool signsDiffer = positive != that.positive; BigInt dividend(*this); BigInt divisor(that); size_t shift = dividend.size() - divisor.size(); std::vector<bool> binaryDigits; dividend.positive = divisor.positive = true; divisor <<= shift; while (divisor > dividend) { divisor >>= 1; shift--; } while (shift) { if (divisor <= dividend) { dividend -= divisor; binaryDigits.push_back(true); } else binaryDigits.push_back(false); --shift; divisor >>= 1; } if (dividend >= divisor) { binaryDigits.push_back(true); dividend -= divisor; } else binaryDigits.push_back(false); std::reverse(binaryDigits.begin(), binaryDigits.end()); *this = BigInt(BigInt::binaryToWords(binaryDigits), positive == that.positive); if (signsDiffer && !dividend.isZero()) *this -= 1; trim(); return *this; }
BigInt BigInt::operator%(const BigInt& second) { BigInt dividend(this); BigInt divisor(second); int startM = dividend.getMagnitude() - divisor.getMagnitude(); divisor.times10ToN(startM); for(int i=startM; i >= 0; --i) { while(absCmp(dividend, divisor)){ dividend -= divisor; } divisor.times10ToN(-1); } return dividend; }
const BigInt operator /(const BigInt& amount1, const BigInt& amount2) { // magn = magnificent; BigInt quotient, magn(amount2), dividend(amount1), divisor(amount2); dividend.sign = divisor.sign = 0; if(dividend < divisor) return BigInt(0); if(dividend > divisor) magn = magn.leftShift(dividend.length - divisor.length); //if(dividend < magn) // magn = magn.rightShift(); // magn = magn/10; if(dividend >= magn) quotient.length = amount1.length - amount2.length + 1; else{ quotient.length = amount1.length - amount2.length; magn = magn.rightShift(); // magn = magn/10; } quotient.digit = new int[quotient.length]; for(int i = 0 ; i < quotient.length ; i++) quotient.digit[i] = 0; int index(0); while(dividend >= divisor){ while(dividend >= magn) { quotient.digit[index]++; dividend = dividend - magn; } magn = magn.rightShift(); index++; } if(amount1.getSign() == amount2.getSign()) return BigInt( quotient.digit , quotient.length, quotient.sign); else return BigInt( quotient.digit , quotient.length, !quotient.sign); }
// Function to process which action to take with current trade void portfolio::action(pTrade input){ // cout << "Enter action" << endl; if(input.sortID == "CD") return; if(input.type == "buy" || input. type == "Buy") buy(input); else if (input.type == "sell" || input.type == "Sell") sell(input); else if (input.type == "donate" || input.type == "Donate") donate(input); else if (input.type == "aquisition" || input.type == "Aquisition") acquistion(input); else if(input.type == "spinoff" || input.type == "Spinoff") spinoff(input); else if(input.type == "reverse split" || input.type == "split") split(input); else if(input.type == "exchange") exchange(input); else if(input.type == "dividend") dividend(input); // cout << "Exit action" << endl << endl; }
virtual std::string message () const { std::stringstream str; str << "Error: Division by zero in " << Intern::intToString (dividend ()) << " " << operation () << " 0 " << TargetTypedNumericException<T>::targetTypeInfo (); return str.str (); }