Function sqrtBig

  • Calculates the nth root of a Big instance with custom precision and rounding mode.

    Note: it's the most weighted function in the library. It's reusing a lot of other functions, and it's not perfect in performance, recommended to use it only when you need it and with default precision and rounding mode. It uses the Newton's method to calculate the root.

    Parameters

    • big: Big

      The Big instance.

    • root: number = 2

      The root to calculate. Must be an integer. Defaults to 2.

    • precision: number = DEFAULT_PRECISION

      The number of decimal places to keep in the result (optional). Defaults to 20.

    • Optional mutable: boolean = false

      Whether to mutate the first Big instance. Defaults to false.

    Returns Big

    The nth root of the Big instance with the specified precision and rounding mode.

    Throws

    • If the root is not an integer.

    Example

    const big1 = new Big(16);
    console.log(sqrtBig(big1).toString()); // 4.00000000000000000000
    console.log(sqrtBig(big1, 4, 0).toString()); // 2
    console.log(sqrtBig(big1, 4, 1).toString()); // 2.0
    console.log(sqrtBig(Big(0), 4).toString()); // 0
    console.log(sqrtBig(Big(1), 4).toString()); // 1
    console.log(sqrtBig(Big(-1), 4).toString()); // throws Error
    console.log(sqrtBig(Big(16), 0.5).toString()); // throws Error
    console.log(sqrtBig(Big(16), -2).toString()); // throws Error
    console.log(sqrtBig(Big(16), 4, -1).toString()); // throws Error

Generated using TypeDoc