Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DIV_NN_Dk.h"
- #include "../COM_NN_D/COM_NN_D.h"
- #include "../MUL_ND_N/MUL_ND_N.h"
- #include "../MUL_Nk_N/MUL_Nk_N.h"
- Natural* DIV_NN_Dk::get(Natural* firstOperand, Natural* secondOperand) const{
- size_t firstOperandLen = firstOperand->len();
- size_t secondOperandLen = secondOperand->len();
- Natural firstDigit("1");
- size_t k;
- if(firstOperandLen < secondOperandLen){
- return new Natural("0"); // the second operand is supposed to be smaller than the first
- } else if(COM_NN_D().get(firstOperand, secondOperand)->get(0) == 0) {
- return new Natural("1"); // the operands are equal
- } else {
- //add check first digit(check how std::copy works)
- bool flag = false;
- for(k = firstOperandLen - 1; k >= 0; --k){// k ?= firstOperand - 1
- Natural divisible(*firstOperand, k, firstOperandLen);
- while(COM_NN_D().get(&divisible, secondOperand)->get(0) == 2){
- secondOperand = MUL_ND_N().get(secondOperand, &firstDigit);
- firstDigit.set(0, firstDigit.get(0) + 1);
- flag = true;
- }
- if(flag){ // found a firstDigit
- if(COM_NN_D().get(&divisible, secondOperand)->get(0) == 1) // confirming that we got an actual first digit
- firstDigit.set(0, firstDigit.get(0) - 1);
- break;
- }
- }
- }
- Natural k(std::vector<uint8_t>{k});
- return new Natural(&MUL_Nk_N().get(&firstDigit, &k));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement