Yeah, I’ve actually written quick and dirty code that used both a division and a modulus, but then went back later to use the former to calculate the latter with a multiplication and a subtraction to get a speed improvement.
There have been other occasions where I’ve been able to replace something like average = sum / count; if average > y with ifsum > count * y, when it’s not entirely obvious that y could be multiplied by anything and remain meaningful.
But when a division can’t be avoided, you still want that genius-written magical library to take some of the sting out of it.
Yeah, I’ve actually written quick and dirty code that used both a division and a modulus, but then went back later to use the former to calculate the latter with a multiplication and a subtraction to get a speed improvement.
There have been other occasions where I’ve been able to replace something like
average = sum / count; if average > ywithif sum > count * y, when it’s not entirely obvious that y could be multiplied by anything and remain meaningful.But when a division can’t be avoided, you still want that genius-written magical library to take some of the sting out of it.
He didn’t do any of that. Just typecast the numbers to be doubles.
The whole benchmark was a mess but that part specifically surprised me.