[ << ] | [ < ] | [ 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)
-
x
must be >= 0. This function returns the square root ofx
, normalized to be >= 0. Ifx
is 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
x
is 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)
-
x
should be >= 0. This function sets*root
tofloor(sqrt(x))
and returns the same value assqrtp
: the boolean value(expt(*root,2) == x)
.
For n
th roots, the classes cl_RA
, cl_I
define the following operation:
bool rootp (const type& x, const cl_I& n, type* root)
-
x
must be >= 0.n
must be > 0. This tests whetherx
is ann
th 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)) >= 0
including the positive imaginary axis and 0, but excluding the negative imaginary axis. The result is an exact number only ifz
is an exact number.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on August 27, 2013 using texi2html 5.0.