Board index » delphi » how to do powers in pascal

how to do powers in pascal

You could try FAQ or else here is the code

FUNCTION Power (InNumber, Exponent: Real): Real;
BEGIN
   If (InNumber = 0.0) Then Power := 0.0 Else         { Zero to any power=0 }
     Power := Exp(Exponent * Ln(InNumber));           { Return power value }
END;

 

Re:how to do powers in pascal


Quote
In article <343242d...@news1.ibm.net>,  <ldeb...@ibm.net> wrote:
>You could try FAQ or else here is the code

>FUNCTION Power (InNumber, Exponent: Real): Real;
>BEGIN
>   If (InNumber = 0.0) Then Power := 0.0 Else         { Zero to any power=0 }

Actually 0^0 is undefined.

Osmo

Re:how to do powers in pascal


Quote
>Subject: Re: how to do powers in pascal
>From: ronka...@cc.helsinki.fi (Osmo Ronkanen)
>Date: Wed, Oct 1, 1997 11:39 EDT
>Message-id: <60tqsf$...@kruuna.Helsinki.FI>

>In article <343242d...@news1.ibm.net>,  <ldeb...@ibm.net> wrote:
>>You could try FAQ or else here is the code

>>FUNCTION Power (InNumber, Exponent: Real): Real;
>>BEGIN
>>   If (InNumber = 0.0) Then Power := 0.0 Else         { Zero to any power=0
>}

>Actually 0^0 is undefined.

>Osmo

And neither is 0 to any nonpositive power...

Re:how to do powers in pascal


Quote
In article <343242d...@news1.ibm.net>, ldeb...@ibm.net wrote:

=>You could try FAQ or else here is the code
=>
=>FUNCTION Power (InNumber, Exponent: Real): Real;
=>BEGIN
=>   If (InNumber = 0.0) Then Power := 0.0 Else         { Zero to any power=0 }

     If (Exponent = 0.0) then Power := 1.0 Else         { Why not this too?}

=>     Power := Exp(Exponent * Ln(InNumber));           { Return power value }
=>END;

Bevyn.

--
disclaimer

not only did i not post this i have never seen any of these letters before in my life.

these opinions represent no one least of all myself.

Re:how to do powers in pascal


In article <doing.this.seems.to.remove-0310971447570...@gl4.cs.auckland.
ac.nz> of Fri, 3 Oct 1997 14:47:57 in comp.lang.pascal.borland, Bevyn
Douglas Quiding <doing.this.seems.to.rem...@most.spam.true.address.is.in

Quote
.reply_to.field> wrote:
>In article <343242d...@news1.ibm.net>, ldeb...@ibm.net wrote:

>=>You could try FAQ or else here is the code
>=>
>=>FUNCTION Power (InNumber, Exponent: Real): Real;
>=>BEGIN
>=>   If (InNumber = 0.0) Then Power := 0.0 Else         { Zero to any power=0 }

>     If (Exponent = 0.0) then Power := 1.0 Else         { Why not this too?}

>=>     Power := Exp(Exponent * Ln(InNumber));           { Return power value }
>=>END;

IMHO, swap those two "If" lines.  AFAIR, by convention zero to the power
zero is put at unity.  Code written fails hard if InNumber<0.0 :-( .

--
John Stockton, Surrey, UK.    j...@merlyn.demon.co.uk    Turnpike v1.12    MIME.
  Web URL: http://www.merlyn.demon.co.uk/ - FAQqish topics, acronyms and links.
  Correct 4-line sig separator is as above, a line comprising "-- " (SoRFC1036)
  Before a reply, quote with ">" / "> ", known to good news readers (SoRFC1036)

Re:how to do powers in pascal


In article <doing.this.seems.to.remove-0310971447570...@gl4.cs.auckland.ac.nz>,
Bevyn Douglas Quiding <bqui...@cs.auckland.ac.nz> wrote:

Quote
>In article <343242d...@news1.ibm.net>, ldeb...@ibm.net wrote:

>=>You could try FAQ or else here is the code
>=>
>=>FUNCTION Power (InNumber, Exponent: Real): Real;
>=>BEGIN
>=>   If (InNumber = 0.0) Then Power := 0.0 Else         { Zero to any power=0 }

>     If (Exponent = 0.0) then Power := 1.0 Else         { Why not this too?}

Because if exponent is zero then the formula below gives 1.

Quote

>=>     Power := Exp(Exponent * Ln(InNumber));           { Return power value }
>=>END;

Osmo

Other Threads