I have implemented a simple function which returns the quotient and remainder when the divisor is the power of 10
:
func getQuotientAndRemainder(num int64, digits uint) (int64, int64) {
divisor := int64(math.Pow(10, float64(digits)))
if num >= divisor {
return num / divisor, num % divisor
} else {
return 0, num
}
}
Just curious, except using directly /
and %
operators, is there any better algorithm to get the the quotient and remainder? Or only in the case when the divisor is the power of 10
?