Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > computing t = pow(-11.5, .333)

Reply
Thread Tools

computing t = pow(-11.5, .333)

 
 
Charles Richmond
Guest
Posts: n/a
 
      05-18-2006
CBFalconer wrote:
>
> John Smith wrote:
> > CBFalconer wrote:
> >

> ... snip ...
> >>
> >> Yes. What you are doing has no meaning. You are actually
> >> returning -(b**x) instead of (-b)**x, where I am using ** to
> >> represent exponentiation. What is the real problem?
> >>
> >> Consider: what is the square root of -1/2? There is no answer in
> >> the real plane. You need complex variables for this. Yet this is
> >> just the value of (-0.5)**0.5.

> >
> > My project involves solving cubic and quartic equations which
> > sometimes have complex roots and I am feeling my way along in the
> > dark. Occasionally there is a faint glimmer of light in the
> > distance. thanks to all for your responses. They have been helpful.

>
> If you want real roots (which may not exist for a quartic, but must
> exist for a cubic) consider a Newton-Raphson solution. Off to the
> books with you. This is now no longer a C question, but
> algorithmic, and better suited to comp.programming.
>

OT: I would recommend Bairstow's method. Google it or see Wikipedia.

--
+----------------------------------------------------------------+
| Charles and Francis Richmond richmond at plano dot net |
+----------------------------------------------------------------+
 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      05-19-2006
Keith Thompson wrote:

> exp(b*ln(a)) is the obvious and mathematically correct way to
> implement pow(a, b), but I've been told that it's not the best way to
> implement it, probably for reasons having to do with numerical
> stability. Sorry, I don't have any details. (Elsethread,
> P.J. Plauger mentions using this formula with extra precision.)


My portable freestanding version of pow,
which uses my freestanding versions of exp and log,
has trouble matching the accuracy my implementation's pow.

pow(0.0001, -0.25) - 10 is 0.000000e+000
fs_pow(0.0001, -0.25) - 10 is 3.552714e-015

There's a lot of squaring in my fs_exp function,
which I suspect is the main problem.
Portable C code doesn't have access to any types
which are guaranteed to be more precise than double.

double fs_exp(double x)
{
unsigned n, square;
double b, e;
static double x_max;

if (1 > x_max) {
x_max = fs_log(DBL_MAX);
}
if (x_max >= x && x >= -x_max) {
for (square = 0; x > 1; x /= 2) {
++square;
}
while (-1 > x) {
++square;
x /= 2;
}
e = b = n = 1;
do {
b /= n++;
b *= x;
e += b;
b /= n++;
b *= x;
e += b;
} while (b > DBL_EPSILON / 4);
while (square-- != 0) {
e *= e;
}
} else {
e = x > 0 ? DBL_MAX : 0;
}
return e;
}


--
pete
 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      05-19-2006
P.J. Plauger wrote:
>
> "pete" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...


> > Portable C code doesn't have access to any types
> > which are guaranteed to be more precise than double.

>
> Unless you write a portable set of extra precision functions...


Thank you.
That's like the next level of a hard video game for me.
But I only write these things for my own amusement anyway,
so I guess it's time to go to the next level.

--
pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Optical Computing: special issue - Natural Computing, Springer optical supercomputing C Programming 0 01-16-2009 12:18 PM
Optical Computing: special issue - Natural Computing, Springer optical supercomputing C Programming 0 12-19-2008 12:22 PM
Razer Tarantula Gaming Keyboard Review at XYZ Computing at XYZ Computing Silverstrand Front Page News 0 11-01-2006 05:13 PM
Samsung Experience (6.17.05) Event Coverage at XYZ Computing Silverstrand Front Page News 3 06-26-2005 07:10 AM
Sunbeam 20-in-1 Superior Panel Review at XYZ Computing Silverstrand Front Page News 1 06-23-2005 03:18 PM



Advertisments