On Wed, Jul 16, 2014 at 8:15 AM, Andrea Faulds <ajf@ajf.me> wrote:
> Nikita Popov doesn’t seem to be a fan of the %% syntax, so it may be subject to change,
> though I think it’s the best I’ve heard so far. ;)
>
Nor am I. Here's a thought though: How about just making / return int
when there's no remainder.
Looking at this code, you might think it's inefficent:
double dres = a / b;
long lres = a / b;
if (a % b) {
return dres;
} else {
return lres;
}
But in fact at -O1, gcc will optimize this (probably clang and others
as well) to a single idivq instruction and only do the cvtsi2sdq in
the dres case.
My point being, we can just make division with an integral result
return a result of integer division without altering the syntax or
adding a perf hit.
-Sara