TURBO PASCAL

Новости

Программы   

Turbo Pascal 

Игры

Документация   

Странности

FAQ

Ссылки

Форум

Гостевая книга

Рассылка

Благодарности

Об авторе

 13: I need a power function but there is none in Turbo Pascal.

 A: Pascals do not have 
an inbuilt power function. You have to write
one yourself. The common, but non-general method is defining
   function POWERFN (number, exponent : real) : real;
     begin
       powerfn := Exp(exponent*Ln(number));
     end;
To make it general use:
   (* Generalized power function by Prof. Timo Salmi *)
   function GENPOWFN (number, exponent : real) : real;
   begin
     if (exponent = 0.0) then
       genpowfn := 1.0
     else if number = 0.0 then
       genpowfn := 0.0
     else if abs(exponent*Ln(abs(number))) > 87.498 then
       begin writeln ('Overflow in GENPOWFN expression'); halt; end
     else if number > 0.0 then
       genpowfn := Exp(exponent*Ln(number))
     else if (number < 0.0) and (Frac(exponent) = 0.0) then
       if Odd(Round(exponent)) then
         genpowfn := -GENPOWFN (-number, exponent)
       else
         genpowfn :=  GENPOWFN (-number, exponent)
     else
       begin writeln ('Invalid GENPOWFN expression'); halt; end;
   end;  (* genpowfn *)
On the lighter side of things an extract from an answer of mine in
the late comp.lang.pascal UseNet newsgroup:
 >anyone point out why X**Y is not allowed in Turbo Pascal?
   The situation in TP is a left-over from standard
   Pascal. You'll recall that Pascal was originally
   devised for teaching programming, not for
   something as silly and frivolous as actually
   writing programs.  :-)
 

 Contents

На первую страницу

Rambler's Top100 Rambler's Top100
PROext: Top 1000

(с)Все права защищены

По всем интересующим вопросам прошу писать на электронный адрес

Hosted by uCoz