I assume you are advancing your x
value at a fixed delta, possibly dependent on the resolution and zoom level.
If you are lucky enough to actually divide by zero you'll produce +Inf
or -Inf
and can check for that, and skip over that value when building your curve (splitting your curve into multiple parts), which solves your problem in that case.
More generally and more often, you won't actually divide by zero but instead will divide by a very small number, producing a result which is a very large number. You should be able to compare that value with the bounds of your viewport. If this value is outside the bounds of your viewport, you can decide to end that curve, and once a new value appears (for a new value of x) that is once again within your viewport you can begin a new curve, thus solving your problem in that case as well.
If you are advancing your x value per-pixel then the above should be a solution.
If you are advancing your x value more coarsely than per-pixel, then you will also have to deal with clipping the line segment, and with avoiding false positives with respect to detecting discontinuity.
Also check to see if your particular library can produce for you a list of analytically determined discontinuities. With such a list ahead of time, you can split your curve into sections separated by those discontinuities.
See also Division by Zero in Computer Arithmetic, Asymptotes, and Discontinuity.