I'd really prefer to get the
individual functions working, for size reasons and to
avoid the whole Mathlib thing if I can.
Here's a square root function that works.
Regards,
Steve Mann
#define TT_MIN_VALUE 1.0e-6
#define TT_ACCURACY 1.0e-6
/***********************************************************************
* FUNCTION: _sqrt
*
* DESCRIPTION: Calculate the square root of a double number using
* successive approximations. The loop stops when the
* difference between two successive iterations is smaller
* than the Tiny Trig accuracy threshold.
*
* RETURNED: The square root or zero if the number is smaller
* than the minimum value handled by the library.
***********************************************************************/
double _sqrt // ( out ) the square root
(
double x // ( in ) The number to get the square root of
)
{
double result = 0.0, prevResult, diff = 0.0;
// Eliminate negatives and small values outside the library range.
if ( x >= TT_MIN_VALUE )
{
result = x;
// Calculate until two successive guesses are less than
// the library's minimum value. # iterations ranges from about
// 10 (for very small and very large #s) to about 5 for numbers
// close to zero.
do
{
prevResult = result;
result = ( result + ( x / result )) / 2.0;
diff = _abs ( prevResult - result );
}
while ( diff > TT_ACCURACY );
}
return result;
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/