Page 1 of 1

Performing Double (data type) division

PostPosted: April 8th, 2008, 1:27 pm
by sekar1
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.

PostPosted: April 8th, 2008, 6:34 pm
by Kambiz
You can use Extended data type if you need more precision.

PostPosted: April 9th, 2008, 4:25 am
by sekar1
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

PostPosted: April 9th, 2008, 4:31 am
by sekar1
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;

PostPosted: April 9th, 2008, 5:06 am
by sekar1
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?

PostPosted: April 9th, 2008, 6:04 pm
by Kambiz
Not so much. Safely use it.