3 ms·
FWIW, I tend to write a lot of error checking code that checks for division by zero ahead of time and just returns zero instead. Found an example: pub
by lamontcg 3y ago
FWIW, I tend to write a lot of error checking code that checks for division by zero ahead of time and just returns zero instead. Found an example:
public double magnitude
{
get
{
double c = max_magnitude;
return c > 0 ? Math.Max(c, c * (this / c)._internal_magnitude) : 0;
}
}
I could delete quite a few if statements in pretty hot codepaths if division by zero just returned zero.
- xxpor 3y agoThis feels like an area where extended/vector instructions could be added to make this fast too. Probably not news to you, but for example, NEON (and likely AVX, I’m just a lot less familiar with it) has saturating addition and subtraction.