Performing Double (data type) division

Please discuss general Delphi programming topics here.

Performing Double (data type) division

Postby sekar1 » April 8th, 2008, 1:27 pm

Hi,

i am facing problem to perform a double data type division

here is the sample code:

Var DoubleX, doulbleY, doubleAns: double;

begin

DoubleX:= 100.123;
DoubleY:= 125.896;

DoubleAns:=(DoubleX-DoubleY)/doubleX;

end;

(I used div operator instead of / i am getting error (Operator not applicable to this operand type) and
" / " operator is working fine only if the data type is of single).

The datatype in this are of fixed, since i need to use the Doubleans for plotting in Tchart which will only take Double datatype yvalues.

is there any approach to perform this easily?

regards,
sekar.
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Postby Kambiz » April 8th, 2008, 6:34 pm

You can use Extended data type if you need more precision.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm

Postby sekar1 » April 9th, 2008, 4:25 am

The precision is not a major issue, the issue i am not able to perform the division operation.

The code is not working properly. i made the sample code for the Extended datatype also. here is the source code.

procedure TForm1.Button1Click(Sender: TObject);
var Extx,Exty,Extans: single;
begin
Extx:= 1258.123;
Exty:= 1247.569;
showmessage('hello world');
Extans:= Extx / exty;
end;

In the above code, the values are of not assigned and the division operation is also failed.

Can anyone explain the reason why the arthimatic operation failed?

If i want to perform the operation means, do i need to include any specific library files?

regards,
dhana
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Postby sekar1 » April 9th, 2008, 4:31 am

in the above sample code i tried for EXtended datatype also
The sample code is

procedure TForm1.Button1Click(Sender: TObject);
var Extx,Exty,Extans: extended;
a: integer;
begin
a:= 10;
Extx:= 1258.123;
Exty:= 1247.569;
showmessage('hello world');
Extans:= Extx / exty;
end;
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Postby sekar1 » April 9th, 2008, 5:06 am

Problem solved.. the code is working fine... if i added some more lines in the end it is working...

And thanks for the suggestion of using extended data type also.

I am having one question. do the Extended data type will reduce the speeding of the program execution?
sekar1
Junior Member
Junior Member
 
Posts: 25
Joined: December 21st, 2006, 5:55 am

Postby Kambiz » April 9th, 2008, 6:04 pm

Not so much. Safely use it.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2421
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: Google Feedfetcher and 2 guests

cron