What is the fastest integer division supporting division by zero no matter what the result is?
Summary: I'm looking for the fastest way to calculate (int) x / (int) y without getting an exception for y==0 . Instead I just want an arbitrary result. Background: When coding image processing algorithms I often need to divide by an (accumulated) alpha value. The most simple variant is plain C code with integer arithmetic. My problem is that I typically get a division by zero error for result pixels with alpha==0 . However this are exactly the pixels where the result doesn't matter at all: I don't care about color values of pixels with alpha==0 . Details: I'm looking for something like: