manpagez: man pages & more
info cln
Home | html | info | man
[ << ] [ < ] [ 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 of x, normalized to be >= 0. If x 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 to floor(sqrt(x)) and returns the same value as sqrtp: 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)

x must be >= 0. n must be > 0. This tests whether x is an nth 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 formula sqrt(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 plane realpart(sqrt(z)) >= 0 including the positive imaginary axis and 0, but excluding the negative imaginary axis. The result is an exact number only if z is an exact number.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on August 27, 2013 using texi2html 5.0.

© manpagez.com 2000-2017
Individual documents may contain additional copyright information.