1 (edited by prahousefamily 2016-08-17 04:35:17)

Topic: How To Use Cal Power(2,3) ???

How edit script for cal number function power(2,3) result = 8

but pascal script not have function cal power

how to edit script for cal help me please !!!!


Result := Power(Strtoint(Form1.Edit1.Text),Strtoint(Form2.Edit1.Text)) ;

Error

Result :=(Strtoint(Form1.Edit1.Text))^(Strtoint(Form2.Edit1.Text)) ;

Error

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: How To Use Cal Power(2,3) ???

Hello my friend,


I have a solution for you but internet is down right now (posting from my phone).

As soon as the link is up, I'll post the function.


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: How To Use Cal Power(2,3) ???

Hello Prahousefamily

A clue in the attachment ?

JB

Post's attachments

Attachment icon POWER.zip 2.57 kb, 554 downloads since 2016-08-18 

Re: How To Use Cal Power(2,3) ???

In the current version there is no function Power.


I have added these functions (Power and IntPower) in the latest beta version, please download here
https://www.dropbox.com/s/582unbatehan1 … a.zip?dl=0


examples:

procedure Form1_Button4_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.Edit6.Value := Power(Form1.Edit4.Value, Form1.Edit5.Value);
end;

procedure Form1_Button4_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.Edit6.Value := IntPower(Form1.Edit4.Value, Trunc(Form1.Edit5.Value));
end;
Dmitry.

5 (edited by prahousefamily 2016-08-18 13:43:20)

Re: How To Use Cal Power(2,3) ???

Hi Mathias Thank You For Example
But It Error And DIsplay

Undeclared indentifier: 'IntPower'

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
Var  Exponent     : Integer;
     Base, Answer : Extended;
begin
    Exponent := StrToInt(Form1.Edit2.Text);
    Base     := StrToFloat(Form1.Edit1.Text);
    Answer   := IntPower(Base,Exponent);
    Form1.Edit3.Text := FloatToStr(Answer);

end;

Or 'IntPower' Declare before begin in Var ???
Or My Current MVD Version is OLD ???

My Visual Database : I Love You
Easy For Beginner Student For Me

6 (edited by prahousefamily 2016-08-18 13:38:04)

Re: How To Use Cal Power(2,3) ???

Hi Dmitry.
I See Your add new function
Happy !!!
Thank You Very Much

https://s4.postimg.org/5o6ewz2jt/2016_08_18_20_27_58.png

Post's attachments

Attachment icon 2016-08-18 20 27 58.png 16.15 kb, 301 downloads since 2016-08-18 

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: How To Use Cal Power(2,3) ???

Hello all,


Of course, it i useless now that Dmitry has added the function to MVD, but just for the beauty of it, here is the function to calculation x power y with just a script:


function XpowerY (base, exponant : Extended) : Extended;
var
    power : Extended;
begin
    if (base < 0) AND (exponant < 0) then   //both x and y are negativ
        begin
            power := 1/Exp(-exponant*Ln(-base));
        end
    else if (base < 0) AND (exponant > 0) then //base is negativ and exponant is positiv
        begin
            power :=  Exp(exponant*Ln(-base))
        end
    else if (base > 0) AND (exponant < 0) then //base is positiv and exponant is negativ
        begin
            power := 1/Exp(-exponant*Ln(base))
        end
    else if (base > 0) AND (exponant > 0) then //base is positiv and exponant is positiv
        begin
            power :=  Exp(exponant*Ln(base));
        end
    else if (base = 0) AND (exponant <> 0) then //if base is 0 exponant <> 0 then result is 0
        begin
            power := 0;
        end
    else if (base <> 0 ) AND (exponant = 0) then // if base <> 0 and exponant is 0 result is always 1
        begin
            power := 1;
        end
    else if (base = 0) AND (exponant = 0) then //if both base and exponant = 0 then result = 1
        begin
            power := 1;
        end;

    //sign correction
    if (base < 0) AND (Frac(exponant/2) <> 0) then result := -power else result := power;
end;

Cheers everybody



Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: How To Use Cal Power(2,3) ???

Hello community MVD. It follows down script what I created to do financial calculations (financial mathematics).

procedure calculo_juros_composto;
var
  PMT, FV, PV, i, n: real;
  inicio: integer;
  p1, p2: real;
  calculou: boolean = false;
begin
   PMT := frmCalc.edPMT.value;
   FV  := frmCalc.edFV.value;
   PV  := frmCalc.edPV.value;
   i   := frmCalc.edi.value/100;
   n   := frmCalc.edn.value;
   inicio := strtoint(frmCalc.chk_begin.sqlValue);

   if (frmCalc.edPMT.text = '') and (frmCalc.edFV.value = 0) then    //calcula PMT com FV = 0
   begin
      calculou := true;
      p1 := power((i + 1),n)-1;
      p2 := power((1 + i),(n - inicio)) * i;
      PMT := PV/(p1/p2);
      frmCalc.edPMT.text := Formatfloat('###,###,#0.00',PMT);
      exit;
   end;
   if (frmCalc.edPV.text = '') and (frmCalc.edFV.value = 0) then    //calcula PV com FV = 0
   begin
      calculou := true;
      p1 := power((i + 1),n)-1;
      p2 := power((1 + i),(n - inicio)) * i;
      PV := PMT/(p2/p1);
      frmCalc.edPV.text := Formatfloat('###,###,#0.00',PV);
      exit;
   end;
   if (frmCalc.edFV.text = '') and (frmCalc.edPV.value = 0) then    //calcula FV com PV = 0
   begin
      calculou := true;
      p1 := power((i + 1),n)-1;
      p2 := i;
      FV := PMT * (p1/p2);
      frmCalc.edFV.text := Formatfloat('###,###,#0.00',FV);
      exit;
   end;
   if (frmCalc.edPMT.text = '') and (frmCalc.edPV.value = 0) then    //calcula PMT com PV = 0
   begin
      calculou := true;
      p1 := power((i + 1),n)-1;
      p2 := i;
      PMT := FV / (p1/p2);
      frmCalc.edPMT.text := Formatfloat('###,###,#0.00',PMT);
      exit;
   end;
   if (frmCalc.edi.text = '') and (frmCalc.edPMT.value = 0) then     //calcula i com PMT = 0
   begin
      calculou := true;
      p1 := FV/PV;
      p2 := power(p1,(1/n));
      i := (p2 - 1)*100;
      frmCalc.edi.text := Formatfloat('###,###,#0.00',i);
      exit;
   end;
   if (frmCalc.edn.text = '') and (frmCalc.edPMT.value = 0) then    //calcula n com PMT = 0
   begin
      calculou := true;
      p1 := FV/PV;
      p2 := i + 1;
      n := ln(p1)/ln(p2);
      frmCalc.edn.text := Formatfloat('##0',n);
      exit;
   end;
   .......................................................................

   if calculou = false then showmessage('o campo a ser calculado deve estar em branco e deve haver um campo com valor = 0 (zero)');

end;

Roberto Alencar