• Approximates the inverse of a function at n using the bisection / binary search method.

    Parameters

    • f: ((x: Decimal) => Decimal)

      The function to approximate the inverse of. It must be monotonically increasing and satisfy f(n) >= n for all n >= 0.

    • n: DecimalSource

      The value to approximate the inverse at.

    • mode: MeanMode = "geometric"

      The mode/mean method to use. See MeanMode

    • iterations: number = DEFAULT_ITERATIONS

      The amount of iterations to perform. Defaults to DEFAULT_ITERATIONS.

    • tolerance: DecimalSource = DEFAULT_TOLERANCE

      The tolerance to approximate the inverse with. Defaults to DEFAULT_TOLERANCE.

    • lowerBound: DecimalSource = 1

      The lower bound to start the search from. Defaults to 1.

    • upperBound: DecimalSource = n

      The upper bound to start the search from. Defaults to n.

    • round: boolean = false

      Whether to round the bound and search only through integers. Defaults to false.

    Returns InverseFunctionApproxResult

    An object containing the approximate inverse value "value" (defaults to the lower bound), the lower bound "lowerBound", and the upper bound "upperBound", all as Decimal instances.

    Use Decimal.increasingInverse instead.

    const f = (x) => x.pow(2);
    const inverse = inverseFunctionApprox(f, 16);
    console.log(inverse.value); // ~3.9999999999999996