# Board index » delphi » Power function

## Power function

Hi guys
I am trying to write an program to calculate armstrong numbers.
I am struggling to use the power function.
Should it just be var := yyy * power(base, exponent);
I'm have problems with this. Should I be using it as procedure

Thanks

## Re:Power function

You might want to look at the message by Timo Salmi entitled
"Turbo Pascal Frequently Asked Questions, a monthly pointer"
in this newsgroup. I think item 13 in that list might be of
particular interest to you.

-- Norbert

##### Quote
> Hi guys
> I am trying to write an program to calculate armstrong numbers.
> I am struggling to use the power function.
> Should it just be var := yyy * power(base, exponent);
> I'm have problems with this. Should I be using it as procedure

> Thanks

## Re:Power function

##### Quote
<ma...@linurati.net> wrote:
> I am struggling to use the power function.
> Should it just be var := yyy * power(base, exponent);

The power function is given in the following FAQ

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland
Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html

## Re:Power function

Timo,

Could you explain under what circumstances would this apply:

"else if abs(exponent*Ln(abs(number))) > 87.498 then"
i.e. a number where power function would not work.  I appreciate it is
mathematics but I just want two numbers which would give the number >
87.498 or overflow.

This is an else statement from your wonderful General Power Function.

Best regards,

##### Quote
Timo Salmi wrote:
>  <ma...@linurati.net> wrote:
> > I am struggling to use the power function.
> > Should it just be var := yyy * power(base, exponent);

> The power function is given in the following FAQ

>  165966 Jan 8 2000 ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip

>    All the best, Timo

> --
> Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
> Department of Accounting and Business Finance  ; University of Vaasa
> mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland
> Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html

## Re:Power function

Dave Wilcox  <dogde...@yahoo.com> wrote:

##### Quote
> Timo,
> Could you explain under what circumstances would this apply:
>      "else if abs(exponent*Ln(abs(number))) > 87.498 then"
> i.e. a number where power function would not work.  I appreciate it is

As far as I recall, it is an overflow test. It is NOT the number
itself (because it would overflow), but its logarithm. Its quite
some time ago that I wrote it, by the way.

Anyway, if one wishes to skip any tests, use the simple format, also
given in the said FAQ item. Like this

function POWERFN (number, exponent : real) : real;
begin
powerfn := Exp(exponent*Ln(number));
end;

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance  ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/>  ; FIN-65101,  Finland
Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html

## Re:Power function

in news:comp.lang.pascal.borland, ma...@linurati.net posted at Fri, 23
May 2003 05:00:48 :-

##### Quote
>I am trying to write an program to calculate armstrong numbers.

Armstrong numbers ?

##### Quote
>I am struggling to use the power function.
>Should it just be var := yyy * power(base, exponent);
>I'm have problems with this. Should I be using it as procedure

Since neither argument is the result, you should be using it as a
function.  Since it is not provided by the language, you need to write,
or copy, it as a function.

The commonly-recommended solution is IMHO over-general.

In most practical cases, it will be known whether the exponent is
integer, half-integer, or general; and whether the base must be integer.
Half-integer can use square root; cases with integer exponents can be
handled by multiplication.

When Exp & Ln are not needed, it is more elegant to avoid them; when the
problem is an integer one, it is inelegant to use floating-point
arithmetic.  But, now that "every" PC has a FPU, it may be quicker.

See <URL:http://www.merlyn.demon.co.uk/pas-math.htm#XtotheY>.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt>   RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.