user3633614
user3633614

Reputation: 1

Math Pow inside another math pow function in C#

Im trying to translate an excel function :

10^(-0,2*7^2+2,74*7+(-4,72))

Which gives me the result = 45708,8

When i try to execute this in my application i get the wrong result everytime.. now im stuck at the result = 0

my c# code is:

destB = (decimal)Math.Pow(10, -0.2 * Math.Pow(Decimal.ToDouble(destB), 2.74 * Decimal.ToDouble(destB)+(-4.72)))

Upvotes: 0

Views: 348

Answers (3)

Ulugbek Umirov
Ulugbek Umirov

Reputation: 12797

What is destB? The translated version:

Math.Pow(10, -0.2 * 7 * 7 + 2.74 * 7 - 4.72)

If 7 is destB, then:

Math.Pow(10, -0.2 * destB * destB + 2.74 * destB - 4.72)

Sample code:

double destB = 7;
double result = Math.Pow(10, -0.2 * destB * destB + 2.74 * destB - 4.72);
Console.WriteLine(result);

C# Demo

P.S. I don't do Math.Pow(destB, 2) since it neither improves readability, neither shortens code.

Upvotes: 1

CharlesNRice
CharlesNRice

Reputation: 3259

This would be the exact translation

var destB = Math.Pow(10, -.2 * Math.Pow(7, 2) + 2.74 * 7 + (-4.72));

Upvotes: 0

Dan Hunex
Dan Hunex

Reputation: 5318

This does it

Math.Pow(10,(-0.2* Math.Pow(7,2)+2.74*7+(-4.72)))

Upvotes: 0

Related Questions