openvdb icon indicating copy to clipboard operation
openvdb copied to clipboard

Divide by zero checks

Open Megidd opened this issue 5 years ago • 2 comments

I noticed that there is no divide-by-zero check here:

        } else {
            // c projects inside the [a,b] interval.
            t = t / denom;                                                   // => Divide
            return a + (ab * t);
        }

Also also there:

    if (Abs(b) > Abs(a)) {
        relError = Abs((a - b) / b);                                    // => Divide
    } else {
        relError = Abs((a - b) / a);                                    // => Divide
    }

I'm not sure whether they would cause any trouble.

Megidd avatar Jul 13 '20 12:07 Megidd

I noticed that there is no divide-by-zero check here:

        } else {
            // c projects inside the [a,b] interval.
            t = t / denom;                                                   // => Divide
            return a + (ab * t);
        }

This is already handled here.

EmperorYP7 avatar Sep 29 '20 14:09 EmperorYP7

@EmperorYP7 Thanks! 😄 In that line, I was specifically concerned about denom variable which is non-negative (can be zero) as commented in the code:

// always nonnegative since denom = ||ab||^2
double denom = ab.dot(ab);

Megidd avatar Sep 30 '20 03:09 Megidd