Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Roots of Any Degree (BigFloat)

root(x, degree, precision, mode) and cbrt(x, precision, mode), also x.root(n) and x.cbrt(), take any positive degree.

They need no series and no deciding loop, because a root is algebraic. The integer degree-th root of a scaled significand brackets the true root between two consecutive integers, and whether it landed on the lower one exactly is the sticky bit; one rounding then finishes the job in each of the seven modes. So an exact root comes out exact — root(8, 3) is 2 in every mode, including the directed ones, where a function that evaluated and then rounded would have to pick a side and both sides would be wrong.

Dividing the exponent is the whole of the scaling. x is s * 2^(q * degree + r) with r below the degree, so the factor of 2^r moves into the significand and the root sits at 2^q. The product is never formed again, which is what keeps a value near the bottom of the exponent range from leaving it.

A negative value has a real root only at an odd degree, and gives a NaN at an even one, the way sqrt does. A nought keeps its sign at an odd degree and loses it at an even one. A degree of nought or less is refused rather than answered.