sqrt

fun sqrt(value: KBigDecimal, scale: Int = 10): KBigDecimal

Calculates the square root of a KBigDecimal using Adaptive Newton-Raphson method.

Optimization Strategy:

  1. Smart Initial Guess: Uses Double approximation to start with ~15 correct digits immediately.

  2. Adaptive Precision: Starts with low precision and doubles it in each Newton step. Doubling precision matches the quadratic convergence of Newton's method. This avoids expensive high-precision division in early steps.

Return

The square root of the input value with the specified precision

Parameters

value

The KBigDecimal to calculate the square root of

scale

The number of decimal places in the result (default: 10)

Throws

if the value is negative