Search code examples
algorithmuser-defined-functionspascalexponentialexponentiation

Exponentiation of real numbers


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.


Solution

  • 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)