@snuffles said:
I should also mention that yes, I profiled the code and this function was a hotspot.
Then you can optimize it further, because callint [code]quotient.integral()[/code] and [code]floor(quotient.to_double())[/code] is basically doing twice the same work. What you should do is decompose [code]quotient[/code] into its numerator [code]num[/code] and denominator [code]dem[/code] and compute [code]rem = num % dem[/code], then if that is not 0, make a new rat_num from [code]num - rem[/code] and [code]dem[/code], and multiply it by [code]increment[/code].
This way, you save one integer division and a round-trip through floats.
Assuming of course that you can get the numerator and denominator (i.e. that the rat_num class is not a complete WTF).