# ligo.skymap.distance.conditional_cdf returns NaN for infinite distances

Original report from @andrew.toivonen:

There are a small fraction of incorrect zero/inf distance values being produced

I think that this is referring to an issue surfaced in the sample code for source-frame chirp mass posteriors that I provided in https://git.ligo.org/publications/o4/cbc/task_forces/-/issues/6#note_993182. That code takes an argument `bin_edges`

described as follows:

```
bin_edges : numpy.ndarray
Array of source-frame chirp mass bin edges, **not**
including the implied leftmost edge at 0 and rightmost
edge at +infinity.
```

I excluded chirp masses of 0 and `\infty`

because I was aware of an issue with distance = `\infty`

(corresponding to chirp mass = 0). For that input value, `ligo.skymap.distance.conditional_cdf`

and `ligo.skymap.distance.marginal_cdf`

return NaN instead of the correct finite value.

There are two reasons why these functions return NaN. First, there is a factor in `bayestar_distance_conditional_cdf`

that is of the form `r \exp(-r^2)`

, which approaches zero as `r \rightarrow \infty`

, but as written evaluates to `inf * 0`

which is NaN. Second, the function `gsl_sf_log_erfc`

(also `gsl_sf_erfc`

) returns NaN for infinite or even extremely large arguments.