I've come across an interesting exercise and it says: Implement a function x^y using standard functions of Turbo Pascal
For integer
variables I can use for
loop but I cannot understand how to work with real
variables in this case.
I've been thinking about how to do this using Taylor series (can't understand how to use it for exponentiation) and I also found out that x^y = exp(y*log(x))
but there is only ln
(natural logarithm) in standard functions...
PS I'm not asking you to write code: give me advise or link or something that will help to solve this problem, please.
log(x) in your formula is natural logarithm, so you can use
without any doubts. Both exp and ln are standard Turbo Pascal functions
(general formula is x^y = b^(y * base-b logarithm of x)
log x base y = ln(x) / ln(y) = (log x base 10)/(log y base 10)
Following link has more information regarding logarithms. Check out the "Changing the Base" section. http://en.wikipedia.org/wiki/List_of_logarithmic_identities
You can change your base to natural logarithm and compute accordingly.
Actually for the above, you do not even need to change bases