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

x^y = exp(y*ln(x))

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.

For x = 3.2, y = 2.5,
Say 3.2^2.5 = m
ln(m) = 2.5*ln(3.2)
Hence m = exp( 2.5 * ln(3.2) )

Actually for the above, you do not even need to change bases

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top