Advertisement
tresonance

logaritme_exponentiel

Sep 4th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. import math
  2.  
  3. def isEven(a):
  4.     return (a & 0x1) == 0
  5.  
  6.  
  7. def intPow(val, exp):
  8.     if exp == 0:
  9.         return 1;
  10.     if isEven(exp):
  11.         return intPow(val * val, exp / 2)
  12.     return val * intPow(val * val, (exp - 1) / 2)  
  13.  
  14.  
  15. def factorial(val):
  16.     if (val <= 0):
  17.         return 1
  18.     return factorial(val-1)*val
  19.  
  20. maxIterations = 150
  21.  
  22. def lnCustom(x):
  23.     if (x == 1):
  24.         return 0
  25.     x = float(x)
  26.     result = 0
  27.     for n in range(1, maxIterations):
  28.         curVal = intPow((x-1)/x, n) / n
  29.         result += curVal
  30.     return result
  31.  
  32. def eCustom(x):
  33.     x = float(x)
  34.     result = 0
  35.     for n in range(0, maxIterations):
  36.         curVal = intPow(x, n)/factorial(n)
  37.         result += curVal
  38.     return result  
  39.  
  40. def fracPow(x, exp):
  41.     return eCustom(lnCustom(x)*exp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement