longdouble sqrtl(x) longdouble x;
{ int e; longdouble z, w; #ifndef UNK short *q; #endif longdouble frexpl(), ldexpl();
if( x <= 0.0 )
{ if( x < 0.0 )
mtherr( "sqrtl", DOMAIN ); return( 0.0 );
}
w = x; /* separate exponent and significand */ #ifdef UNK
z = frexpl( x, &e ); #endif
/* Note, frexp and ldexp are used in order to *handledenormalnumbersproperly.
*/ #ifdef IBMPC
z = frexpl( x, &e );
q = (short *)&x; /* point to the exponent word */
q += 7; /* e=((*q>>4)&0x0fff)-0x3fe; *q&=0x000f; *q|=0x3fe0; z=x;
*/ #endif #ifdef MIEEE
z = frexpl( x, &e );
q = (short *)&x; /* e=((*q>>4)&0x0fff)-0x3fe; *q&=0x000f; *q|=0x3fe0; z=x;
*/ #endif
/* approximate square root of number between 0.5 and 1 *relativeerroroflinearapproximation=7.47e-3
*/ /* x=0.4173075996388649989089L+0.59016206709064458299663L*z;
*/
/* quadratic approximation, relative error 6.45e-4 */
x = ( -0.20440583154734771959904L * z
+ 0.89019407351052789754347L) * z
+ 0.31356706742295303132394L;
/* adjust for odd powers of 2 */ if( (e & 1) != 0 )
x *= SQRT2;
/* re-insert exponent */ #ifdef UNK
x = ldexpl( x, (e >> 1) ); #endif #ifdef IBMPC
x = ldexpl( x, (e >> 1) ); /* *q+=((e>>1)&0x7ff)<<4; *q&=077777;
*/ #endif #ifdef MIEEE
x = ldexpl( x, (e >> 1) ); /* *q+=((e>>1)&0x7ff)<<4; *q&=077777;
*/ #endif
/* Newton iterations: */ #ifdef UNK
x += w/x;
x = ldexpl( x, -1 ); /* divide by 2 */
x += w/x;
x = ldexpl( x, -1 );
x += w/x;
x = ldexpl( x, -1 );
x += w/x;
x = ldexpl( x, -1 ); #endif
/* Note, assume the square root cannot be denormal, *soitissafetouseintegerexponentoperationshere.
*/ #ifdef IBMPC
x += w/x; /* *q -= 1;*/
x *= 0.5L;
x += w/x; /* *q -= 1;*/
x *= 0.5L;
x += w/x; /* *q -= 1;*/
x *= 0.5L;
x += w/x; /* *q -= 1;*/
x *= 0.5L; #endif #ifdef MIEEE
x += w/x;
*q -= 1;
x += w/x;
*q -= 1;
x += w/x;
*q -= 1;
x += w/x;
*q -= 1; #endif
return(x);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-14)
¤
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.