Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions include/functions/math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,60 @@ BigInt lcm(const std::string& num1, const BigInt& num2){
return lcm(BigInt(num1), num2);
}

/*
decimal(BigInt, BigInt, Integer)
-------------------
*/
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also mention here what this method does.

BigInt decimal(const BigInt& divisor, const BigInt& dividend, const long long& max_length = 10){
BigInt result;
BigInt decimal_divisor = divisor % dividend;
int current;

while (decimal_divisor % dividend != 0 and result.to_string().length() < max_length){
decimal_divisor *= 10;
current = (decimal_divisor / dividend).to_int();
decimal_divisor %= dividend;
result *= 10;
result += current;
}
return result;
}


/*
decimal(String, BigInt, Integer)
-------------------
*/
BigInt decimal(std::string divisor, BigInt dividend, long long max_length = 10){
return decimal(BigInt(divisor), dividend);
}


/*
decimal(Integer, BigInt, Integer)
-------------------
*/
BigInt decimal(long long divisor, BigInt dividend, long long max_length = 10){
return decimal(BigInt(divisor), dividend);
}


/*
decimal(BigInt, String, Integer)
-------------------
*/
BigInt decimal(BigInt divisor, std::string dividend, long long max_length = 10){
return decimal(divisor, BigInt(dividend));
}


/*
decimal(BigInt, Integer, Integer)
-------------------
*/
BigInt decimal(BigInt divisor, long long dividend, long long max_length = 10){
return decimal(divisor, BigInt(dividend));
}


#endif // BIG_INT_MATH_FUNCTIONS_HPP