Turning division by zero to zero with basic math operators

53 Views Asked by At

I need to compute $\frac{const}{y}$, where $y$ may equal $0$ to present PC state in a human-readable format from exposed internal registers. Is it possible to build an expression of basic math operators ($+$, $-$, $/$, $($, $)$, $*$, $a^b$, $\ln(a)$) that evaluates to $0$, when $y=0$, and to $\frac{const}{y}$ otherwise? The resulting expression may be as complex as necessary, but may include only the listed operators.

There is a similar question, with a different result as a "fallback" value.

1

There are 1 best solutions below

2
On

Using the idea from this answer: $$\frac{const*(1-0^y)}{y+0^y}$$