Math operators is C. Exponent operator?
Author Message Math operators is C. Exponent operator?

Hi.  I am still a little confused as to why standard ANSI C does not
include a normal power operator like for example 2^3.74 (two to the
power of 3.74).  How do people calculate fractional exponents in C (or
C++) given there is no exponent operator supported (^ or **) and one can
not just use a direct multiplying loop?  Doses a person find a stardard
library or header some where or does a person typically just us a
fortran subroutine to handle the math that is compiled in.  I really
would like to know how to do math problems in C.  Any help is
appreciated.  Thanks,

MTY

Sun, 18 Nov 2001 03:00:00 GMT  Math operators is C. Exponent operator?
The operator "^" is reserved for another purpose in C and C++. You must use
the functions defined in math.h to accomplish your goal.

--

Paul Lutus
www.arachnoid.com

Quote:

> Hi.  I am still a little confused as to why standard ANSI C does not
>include a normal power operator like for example 2^3.74 (two to the
>power of 3.74).  How do people calculate fractional exponents in C (or
>C++) given there is no exponent operator supported (^ or **) and one can
>not just use a direct multiplying loop?  Doses a person find a stardard
>library or header some where or does a person typically just us a
>fortran subroutine to handle the math that is compiled in.  I really
>would like to know how to do math problems in C.  Any help is
>appreciated.  Thanks,

>MTY

Sun, 18 Nov 2001 03:00:00 GMT  Math operators is C. Exponent operator?

Quote:

> > Hi.  I am still a little confused as to why standard ANSI C does not
> >include a normal power operator like for example 2^3.74 (two to the
> >power of 3.74).  How do people calculate fractional exponents in C (or
> >C++) given there is no exponent operator supported (^ or **) and one can
> >not just use a direct multiplying loop?  Doses a person find a stardard
> >library or header some where or does a person typically just us a
> >fortran subroutine to handle the math that is compiled in.  I really
> >would like to know how to do math problems in C.  Any help is
> >appreciated.  Thanks,

> The operator "^" is reserved for another purpose in C and C++. You must
use
> the functions defined in math.h to accomplish your goal.

Welcome back, Paul. Did you get very wet?

Perhaps the OP would have been grateful to have been told specifically of
the pow() function? :-)

--
Richard Heathfield

The bug stops here.

Sun, 18 Nov 2001 03:00:00 GMT  Math operators is C. Exponent operator?
<off-topic>

Actually, a nice long road trip. Met an 800-pound grizzly, face-to-face, on
a trail in Montana.

</off-topic>

<< Perhaps the OP would have been grateful to have been told specifically of
the pow() function? >>

I actually considered the content of the original post and realized he would
do very well to browse the entire file math.h -- or the relevant section of
a textbook. Otherwise, I would be providing a fact, not an idea :)

--

Paul Lutus
www.arachnoid.com

<snip>

Quote:
>Welcome back, Paul. Did you get very wet?

>Perhaps the OP would have been grateful to have been told specifically of
>the pow() function? :-)

>--
>Richard Heathfield

>The bug stops here.

Sun, 18 Nov 2001 03:00:00 GMT  Math operators is C. Exponent operator?

Quote:

>         Hi.  I am still a little confused as to why standard ANSI C does not
> include a normal power operator like for example 2^3.74 (two to the
> power of 3.74).  How do people calculate fractional exponents in C (or
> C++) given there is no exponent operator supported (^ or **) and one can
> not just use a direct multiplying loop?

As any mathematician does.

Quote:
> Doses a person find a stardard
> library or header some where or does a person typically just us a
> fortran subroutine to handle the math that is compiled in.  I really
> would like to know how to do math problems in C.  Any help is
> appreciated.  Thanks,

You could use something like (untested, no error handling):

double DoublePower(double base,double exponent)
{
return exp(exponent*log(base));
}
...
x=DoublePower(2.0,3.74);

Hope it helps.

--

Graz, Austria   www.hls-software.com

Sun, 18 Nov 2001 03:00:00 GMT

 Page 1 of 1 [ 5 post ]

Relevant Pages