Any build macro to compute the powers of int number?

P

PengYu.UT

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
 
B

Ben Pfaff

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.
 
C

Chris Croughton

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
 
W

Walter Roberson

: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))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top