Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://stackoverflow.com/a/466434/848344
- public decimal powVappolinario(decimal x, decimal y)
- {
- return DecimalExp(y * LogN(x));
- }
- public decimal Exponentiate(decimal a, decimal b)
- {
- decimal total = a;
- for (int i = 1; i < b; i++) total = a*total;
- return total;
- }
- public int Factorial(int n)
- {
- int j=1;
- for(int i=1;i<=n;i++){ j = j*i; }
- return j;
- }
- // Adjust this to modify the precision
- public const int ITERATIONS = 27;
- // power series
- public decimal DecimalExp(decimal power)
- {
- int iteration = ITERATIONS;
- decimal result = 1;
- while (iteration > 0)
- {
- decimal fatorial = Factorial(iteration);
- result += Exponentiate(power, iteration) / fatorial;
- iteration--;
- }
- return result;
- }
- // natural logarithm series
- public decimal LogN(decimal number)
- {
- decimal aux = (number - 1);
- decimal result = 0;
- int iteration = ITERATIONS;
- while (iteration > 0)
- {
- result += Exponentiate(aux, iteration) / iteration;
- iteration--;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement