While quadgk can handle integrable singularities at the endpoints (because it never evaluates the integrand exactly at the endpoints), singularities or discontinuities in the interior of the integration domain can cause errors (like DomainError) or extremely slow convergence.
To resolve this, use the syntax quadgk(f, a, b, c, ...) to subdivide the integral into multiple segments: $\int_a^b f(x)dx + \int_b^c f(x)dx + \dots$. By adding the location of the singularity or discontinuity as an extra endpoint, you ensure the algorithm handles the non-smooth behavior more efficiently.
You can also reduce the number of evaluations for subdivided intervals by lowering the order parameter.
# Problem: Singularity at x=1 in the interval (0, 2)
# This might fail or be slow:
quadgk_count(x -> 1/sqrt(abs(x-1)), 0, 2)
# Solution: Subdivide at the singularity
quadgk_count(x -> 1/sqrt(abs(x-1)), 0, 1, 2)
# Problem: Discontinuity at x=1
# Solution: Subdivide and optionally lower the order
quadgk_count(x -> x > 1, 0, 1, 3, order=1)