exponential

  • Thread starter Thread starter vinnie
  • Start date Start date
V

vinnie

if i am building a console application, what code should i us to make
an exponential operation?

For example 4^2 = 8

If i use the ^ symbol, i get an error

thanks
 
vinnie said:
how?

deciaml a = 4;
decimal b = 3;

then?

Math.Pow(a,b) works for double, int etc. but not for
decimal.

If the second argument really is decimal, then I think you will
need to convert to double, pow and then convert the result back.

If the second argument is really an integer (which seems more
likely), then you can easily write your own Pow.

Arne
 
vinnie said:
how?

deciaml a = 4;
decimal b = 3;

then?

There's nothing in the framework that provides powers for decimals.
You'd have to use doubles instead. You can cast back to decimal
afterwards, of course.

decimal a = 4;
decimal b = 3;

decimal x = (decimal) Math.Pow((double)a, (double)b);
 
if i am building a console application, what code should i us to make
an exponential operation?

For example 4^2 = 8

If i use the ^ symbol, i get an error

thanks

If you want to obtain 8 from the numbers 4 and 2, maybe the error is the
operation you are applying: try to substitute the ^ symbol with the * symbol
and everything should work.

^_^
 
maybe the error is the operation you are applying

The odd thing is: I didn't even look at the math! (and I'm normally a
pedant...)

Good spot ;-p

Marc
 

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

Similar Threads


Back
Top