Math cond bug? Division by zero

An error was encountered while using division, math cond did not work:

But + is normal:


Hi @youyin123,

This seems like a bug. I was able to reproduce this on 20.07 version. What version are you using ?

also - Dgraph version: v20.07.0.

If it can be solved, please let me know.

Hey guys. I don’t think it is an issue. Dgraph explicitly says that it doesn’t dive by zero. In real-world math, divisions also aren’t divisible by zero. Am I missing something?

I have used the math(cond()) function to handle 0 :


Yeah, but the part zombieLikeCount/totalLikeCount is pure math. It will do math and return true or false for that. In that case, Dgraph doesn’t divide by zero.

You mean that in cond (A, B, C), A, B, C are calculated at the same time?

Here, the judgment of A only determines whether B or C is returned.
Instead of what I understand, judge whether a is true or false, and then decide whether to execute B or C?????????

Cond is a function with 3 operands. The first operand will be checked and return true or false. If false*, it will execute the third operand. In that scenario, the division operation will happen.

As Dgraph math func doesn’t divide by zero, this query is invalid. What you could try is to increase the value on the variable that returns zero. So the division will happen by an integer value.