import math


def equal(a, b, abstol=1e-16, reltol=0, mathlib=math):
    """Check if two values are equal.

    By default, we test with (absolute) tolerances. This can be changed as desired.
    For exact equality, set abstol=reltol=0.

    mathlib allows to specify the module from which isclose should be used: numpy, math, or custom.
    A custom module needs to implement .__name__ and .isclose(a, b, abstol=__, reltol=__)
    """

    # depending on choice of function, assign tolerances
    if mathlib.__name__ == 'math':
        tols = dict(abs_tol=abstol, rel_tol=reltol)
    elif mathlib.__name__ == 'numpy':
        tols = dict(atol=abstol, rtol=reltol)
    else:
        tols = dict(abstol=abstol, reltol=reltol)

    # call function with values
    return mathlib.isclose(a, b, **tols)