Thanks Steve, that works great!
I don't suppose you have something similar for an
arctan function? That's the other one I'm having
problems with from FDLibM. I'm actually using the
atan2() function, which calls atan(). Here are my
results from calling __ieee754_atan2(y,x):
__ieee754_atan2(0,0) = 0 rad = 0 degree
__ieee754_atan2(0,1) = 0 rad = 0 degree
__ieee754_atan2(0,-1) = Pi rad = 180 degree
__ieee754_atan2(1,0) = Pi/2 rad = 90 degree
__ieee754_atan2(1.0, 1.0) = 1 rad = 57 degrees
__ieee754_atan2(1.0, -1.0) = 4.14159 rad = 237 degrees
__ieee754_atan2(-1,0) = -Pi/2 rad = -90 degree
__ieee754_atan2(2.0, 1.0) = 2 rad = 115 degrees
__ieee754_atan2(-1.0, -1.0) = -2.14159 rad = -122
degrees
__ieee754_atan2(-1.0, -2.0) = -2.6416 rad = -151
degrees
Brian
--- In [EMAIL PROTECTED], Steve Mann
<[EMAIL PROTECTED]> wrote:
> >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/
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/