How to return a zero if either of the two components is zero?

Yes, of course. Often this is precisely the measurement that we aim for.