Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!mcsun!hp4nl!phigate!cnps!jeroenk From: jeroenk@cnps.PHILIPS.nl (Jeroen Kessels) Newsgroups: comp.lang.pascal Subject: Re: TP: Exponentiation? Message-ID: <1256@cnps.PHILIPS.nl> Date: 25 Jul 90 11:35:09 GMT References: <950036@hpclapd.HP.COM> Organization: Philips C&P-LSS Lines: 38 defaria@hpclapd.HP.COM (Andy DeFaria) writes: > how to you do exponentiation in TP 4.0 (or 5.0 or 5.5). > ... > the usually "**" operator only produced a compile error. What gives? If you mean 'exponential' (e raised to the x'th power) then try the 'exp()' function. If you mean 'exponentiate' (x raised to the y'th power) then you could use the following function of mine, there is no ready-made function. {$N+} function Power(x, y : extended) : extended; { Return x to the power of y. Note: a non-integer power of a negative number is not defined in mathematics. This routine will therefore round y to an integer if x is negative. } var i : longint; begin if x > 0 then Power := exp(y*ln(x)) else if x = 0.0 then Power := 0.0 else begin i := round(int(y)); if odd(i) then Power := -exp(ln(abs(x)) * i) else Power := exp(ln(abs(x)) * i); end; end; -- Jeroen C. Kessels Software Engineer, Philips C&P-LSS VA-25, P.O. Box 218, 5600 MD Eindhoven, The Netherlands Uucp = jeroenk@cnps.philips.nl