| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.7 Roots
Each of the classes cl_R,
cl_F, cl_SF, cl_FF, cl_DF, cl_LF
defines the following operation:
type sqrt (const type& x)-
xmust be >= 0. This function returns the square root ofx, normalized to be >= 0. Ifxis the square of a rational number,sqrt(x)will be a rational number, else it will return a floating-point approximation.
The classes cl_RA, cl_I define the following operation:
bool sqrtp (const type& x, type* root)-
This tests whether
xis a perfect square. If so, it returns true and the exact square root in*root, else it returns false.
Furthermore, for integers, similarly:
bool isqrt (const type& x, type* root)-
xshould be >= 0. This function sets*roottofloor(sqrt(x))and returns the same value assqrtp: the boolean value(expt(*root,2) == x).
For nth roots, the classes cl_RA, cl_I
define the following operation:
bool rootp (const type& x, const cl_I& n, type* root)-
xmust be >= 0.nmust be > 0. This tests whetherxis annth power of a rational number. If so, it returns true and the exact root in*root, else it returns false.
The only square root function which accepts negative numbers is the one
for class cl_N:
cl_N sqrt (const cl_N& z)-
Returns the square root of
z, as defined by the formulasqrt(z) = exp(log(z)/2). Conversion to a floating-point type or to a complex number are done if necessary. The range of the result is the right half planerealpart(sqrt(z)) >= 0including the positive imaginary axis and 0, but excluding the negative imaginary axis. The result is an exact number only ifzis an exact number.
| [ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on August 27, 2013 using texi2html 5.0.
