473,320 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Any build macro to compute the powers of int number?

Hi All,

For example, I want to declare an array

double array[VERY_VERY_VERY_LONG_NAME * VERY_VERY_VERY_LONG_NAME *
VERY_VERY_VERY_LONG_NAME * VERY_VERY_VERY_LONG_NAME];

Of cause, I can define an macro for the 4th power of
VERY_VERY_VERY_LONG_NAME. But I want to know whether there is any build
in macro to compute the powers. Thanks!

Best wishes,
Peng

Nov 14 '05 #1
4 6210
"Pe*******@gmail.com" <Pe*******@gmail.com> writes:
double array[VERY_VERY_VERY_LONG_NAME * VERY_VERY_VERY_LONG_NAME *
VERY_VERY_VERY_LONG_NAME * VERY_VERY_VERY_LONG_NAME];

Of cause, I can define an macro for the 4th power of
VERY_VERY_VERY_LONG_NAME. But I want to know whether there is any build
in macro to compute the powers. Thanks!


No.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #2
In article <11**********************@z14g2000cwz.googlegroups .com>,
Pe*******@gmail.com <Pe*******@gmail.com> wrote:
:Of cause, I can define an macro for the 4th power of
:VERY_VERY_VERY_LONG_NAME. But I want to know whether there is any build
:in macro to compute the powers. Thanks!

pow() is the closest, but it is a function not a macro, and it takes
and returns double, not int. Not suitable for a constant subscript
in other words.

You could do the usual -- define a macro for x*x and then
x**4 is square(square(x))
--
Feep if you love VT-52's.
Nov 14 '05 #3
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.ca> wrote in message
news:d1f32f$rn6

<snip>
You could do the usual -- define a macro for x*x and then
x**4 is square(square(x))

#define POW4(x) ((x)*(x)*(x)*(x))

is shorter. :-)

--
Tor <torust AT online DOT no>

Nov 14 '05 #4
On 18 Mar 2005 09:05:59 -0800, Pe*******@gmail.com
<Pe*******@gmail.com> wrote:
For example, I want to declare an array

double array[VERY_VERY_VERY_LONG_NAME * VERY_VERY_VERY_LONG_NAME *
VERY_VERY_VERY_LONG_NAME * VERY_VERY_VERY_LONG_NAME];

Of cause, I can define an macro for the 4th power of
VERY_VERY_VERY_LONG_NAME. But I want to know whether there is any build
in macro to compute the powers. Thanks!


No. That was an easy one <g>. Your best bet is as you say to define a
macro to do it:

#define POW4(a) ((a)*(a)*(a)*(a))

(don't forget the parentheses otherwise POW4(1+2) will have really weird
effects!)

But if you need POW(x,y) where both are macros, I'm afraid you're stuck.
The C preprocessor isn't that pow-erful (sorry, couldn't resist the
pun!)...

Chris C
Nov 14 '05 #5

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

Similar topics

0
by: Yosh | last post by:
Is there a way to get the version number of the build and use it in a post build event macro? I hope this makes sense? David
0
by: Igor | last post by:
Hi all! As many of you, I have a big VB.NET solution and quite often get bogus build errors out of the blue. This isn't declared, that is not a property of some shit and so on... It's very...
1
by: Terry | last post by:
New to C# and the VS IDE so apologies to the old sweats for such a basic question. Is there a why to program the retrieval of the build number? I am looking to add this to an xml file every...
3
by: David Battams | last post by:
Hi there, I'm calling xcopy in a post build event to copy some runtime requirements to the TargetDir of the application I am working on. Problem is that I only seem to be able to have 9 calls to...
22
by: MLH | last post by:
If 3 things can be in one of 2 states, the number of possible combinations is equal to 2^3. But if I have 3 things, 2 of which can be in 2 states and the other in 3 states, what's the simplest...
34
by: Umesh | last post by:
how to convert a program to a function/macro and put it in a header file? is there any shortcut method for this? thanks.
12
by: Fabrice | last post by:
Hi, Lets say I want to define a generic macro to swap bytes in a integer: #define swapbytes(x) ... I have several implementation of the macros, one is generic C, the other one will be an...
3
by: SANJINJIT | last post by:
Hi, I have a spreadsheet looks like this: QID C1 C2 C3 C4 %a %b %c %d 13123 b b b b 0% 100% 0% 0% 13124 d d d d 0% 0% 0% ...
10
by: Bin Chen | last post by:
switch(i) { case 1: break; case 2: break; case N: break; }
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.