Power function 
Author Message
 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



Tue, 08 Nov 2005 20:00:48 GMT  
 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



Tue, 08 Nov 2005 23:45:19 GMT  
 Power function

Quote:

> 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
 tsfaqp.zip Common Turbo Pascal Questions and Timo's answers, linked

   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

Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html



Wed, 09 Nov 2005 02:22:57 GMT  
 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:


> > 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
>  tsfaqp.zip Common Turbo Pascal Questions and Timo's answers, linked

>    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

> Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html



Wed, 09 Nov 2005 11:18:28 GMT  
 Power function

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

Timo's  FAQ  materials  at   http://www.uwasa.fi/~ts/http/tsfaq.html



Wed, 09 Nov 2005 20:34:47 GMT  
 Power function


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>.

--

  <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.



Wed, 09 Nov 2005 19:32:38 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. power function: looking to improve this one.

2. Power function

3. Power Function

4. HELP : Power Function

5. Trig and Power functions (follow up)

6. power function???

7. Recursive power of 2 function

8. Recursive power of 2 function

9. Trig Functions and Powers

10. How do I make a 'Power(Base,Exp)' function??

11. Turbo Pascal for Windows and Round function and randomize function

12. why define a function w/in another function?

 

 
Powered by phpBB® Forum Software