473,473 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to represent interger powers in C++?

such as 3^4 ?

Dec 6 '06 #1
3 16574
I believe there to be no such representation.
Try:

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

Joseph.

Dec 6 '06 #2
"heng" <li*********@gmail.comwrote:
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.
Dec 6 '06 #3
heng wrote:
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/
Dec 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dsptechie | last post by:
I wanted to how exactly malloc() function works. I came to know that malloc() allocates memory only in powers of 2. i.e if asked for say 17 bytes , in the process, it allocates 32 bytes and returns...
22
by: Fred Ma | last post by:
I'm using the expression "int a = ceil( SomeDouble )". The man page says that ceil returns the smallest integer that is not less than SomeDouble, represented as a double. However, my...
2
by: Tim::.. | last post by:
Can someone tell me how I get around the following error? I keep getting the following error on the "RETURN ddlDataSet" line of my code! I don't know how to get arround this and would be grateful...
2
by: guoqi zheng | last post by:
We can enum to represent a interger using a string. But how can we use enum to represent string below is what I want to achieve. Public Enum country Netherlands = "nl" America = "US" France...
7
by: Camellia | last post by:
hi all, I wrote a "table of powers" program and made the 5th power the highest, but when I tried to run the program I found a problem. Here's the output: Integer Square power...
2
by: William Manley | last post by:
Is there a way to check if a string can be a interger without crashing the program?
40
by: KG | last post by:
Could any one tell me how to reverse the bits in an interger?
1
by: www.phpbasic.com | last post by:
i have a problem with interger number in PHP <?php class read{ var $num; function read($num){ $this->num = $num; } function basic(){ print "NUM: ".($this->num); }
5
by: PlayHard | last post by:
I currently have a interger field with this format (YYYYMMDD) Example 20071118 I want to automate a weekly report Sun - Sat, therefore do not want to hard code the date. I want to say (Current...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.