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  
 
 [ 5 post ] 

 Relevant Pages 

1. Exponent operator

2. Access Violation and the dereference operator in C.

3. parallel math operator

4. comparision operator ignore type cast operators

5. Which is faster relational operator or equality operator?

6. VC++ 5.0 ambiguity: conversion operator vs overloaded operator?

7. Comma operator in #define's (was Re: Usage of comma operator)

8. MFC CString operator= conflicts with stl operator template

9. == and != operator (operator overloading)

10. Need help doing math functions (exponents, roots, etc)

11. Does "pairing" relational operators make Operator Overloading safer?

 

 
Powered by phpBB® Forum Software