struct fp_ext *fp_fsqrt(struct fp_ext *dest, struct fp_ext *src)
{ struct fp_ext tmp, src2; int i, exp;
dprint(PINSTR, "fsqrt\n");
fp_monadic_check(dest, src);
if (IS_ZERO(dest)) return dest;
if (dest->sign) {
fp_set_nan(dest); return dest;
} if (IS_INF(dest)) return dest;
/* *sqrt(m)*2^(p),ife=2*p *sqrt(m*2^e)= *sqrt(2*m)*2^(p),ife=2*p+1 * *Soweusethelastbitoftheexponenttodecidewhetherto *usethemor2*m. * *Sinceonlythefractionalpartofthemantissaisstoredand *theintegerpartisassumedtobeone,weplacea1or2into *thefixedpointrepresentation.
*/
exp = dest->exp;
dest->exp = 0x3FFF; if (!(exp & 1)) /* lowest bit of exponent is set */
dest->exp++;
fp_copy_ext(&src2, dest);
/* *Thetaylorrowaroundaforsqrt(x)is: *sqrt(x)=sqrt(a)+1/(2*sqrt(a))*(x-a)+R *Witha=1thisgives: *sqrt(x)=1+1/2*(x-1) *=1/2*(1+x)
*/ /* It is safe to cast away the constness, as fp_one is normalized */
fp_fadd(dest, (struct fp_ext *)&fp_one);
dest->exp--; /* * 1/2 */
/* *Wenowapplythenewtonruletothefunction *f(x):=x^2-r *whichhasanullpointonx=sqrt(r). * *Itgives: *x':=x-f(x)/f'(x) *=x-(x^2-r)/(2*x) *=x-(x-r/x)/2 *=(2*x-x+r/x)/2 *=(x+r/x)/2
*/ for (i = 0; i < 9; i++) {
fp_copy_ext(&tmp, &src2);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.