X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fmath%2Fsqrt.c;h=802f4ce20e7f8a9990f5fc2aecb5bd0316c73c4b;hp=3c6c1266f020b612c0e0c30efbedb2c1c5600ad1;hb=1d9d92ba957a0b8307c9a65c35867fde68e6533b;hpb=34893ecc2200dc7017c36a54cb6c5f4c2378b5ec diff --git a/functions/math/sqrt.c b/functions/math/sqrt.c index 3c6c126..802f4ce 100644 --- a/functions/math/sqrt.c +++ b/functions/math/sqrt.c @@ -1,19 +1,27 @@ -// ---------------------------------------------------------------------------- -// $Id$ -// ---------------------------------------------------------------------------- -// Public Domain C Library - http://pdclib.sourceforge.net -// This code is Public Domain. Use, modify, and redistribute at will. -// ---------------------------------------------------------------------------- +/* ---------------------------------------------------------------------------- + * $Id$ + * ---------------------------------------------------------------------------- + * Public Domain C Library - http://pdclib.sourceforge.net + * This code is Public Domain. Use, modify, and redistribute at will. + * --------------------------------------------------------------------------*/ -// ---------------------------------------------------------------------------- -// C++ - -float sqrt( float x ) { /* TODO */ }; -long double sqrt( long double x ) { /* TODO */ }; +double sqrt( double x ) { /* TODO */ }; -// ---------------------------------------------------------------------------- -// Standard C +/* Therx code +{ + double i = x / 2; + if ( x < 0 ) + { + return 0; + } + // (15 DP) HOW GET MORE? + while ( ( fabs( i - ( x / i ) ) / i ) > 0.000000000000001) + { + i = ( i + ( x / i ) ) / 2; + } + return i; +} +*/ -double sqrt( double x ) { /* TODO */ }; float sqrtf( float x ) { /* TODO */ }; long double sqrtl( long double x ) { /* TODO */ };