Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 6th, 2006, 02:25 AM
heng
Guest
 
Posts: n/a
Default How to represent interger powers in C++?

such as 3^4 ?

  #2  
Old December 6th, 2006, 02:45 AM
Joseph Paterson
Guest
 
Posts: n/a
Default Re: How to represent interger powers in C++?

I believe there to be no such representation.
Try:

#include <cmath>
float result = pow(3.0, 4.0)

Joseph.

  #3  
Old December 6th, 2006, 02:45 AM
Daniel T.
Guest
 
Posts: n/a
Default Re: How to represent interger powers in C++?

"heng" <likemursili@gmail.comwrote:
Quote:
such as 3^4 ?
/* pow example */
#include <cstdio>
#include <cmath>

using namespace std;

int main ()
{
cout << "7 ^ 3 = " << pow( 7, 3 ) << '\n';
cout << "4.73 ^ 12 = " << pow( 4.73, 12 ) << '\n';
cout << "32.01 ^ 1.54 = " << pow( 32.01, 1.54 ) << '\n';
}

--
To send me email, put "sheltie" in the subject.
  #4  
Old December 6th, 2006, 03:05 AM
Steven T. Hatton
Guest
 
Posts: n/a
Default Re: How to represent interger powers in C++?

heng wrote:
Quote:
such as 3^4 ?
Option 1) write your own function. (but overloading won't work for
builtins.)
Option 2) Post to comp.std.c++ and suggest it be added.
Option 3) Use the morally unsound conversion to and from floating point
functionality provided with the Standard Library.

There are two other options, but they amount to impractical academic
exercises. These are to use Cpp meta-programming or template
meta-programming.
--
NOUN:1. Money or property bequeathed to another by will. 2. Something handed
down from an ancestor or a predecessor or from the past: a legacy of
religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles