We help IT Professionals succeed at work.

# Numbers & Delphi

on
605 Views
Hello,

I am using Delphi 2009, And I have the below code, Which make some calculations and the Result should appear in (Edit2) Editbox. I have 7 Machines running my Application, I run my application on all 7 machines to get the result  and Result was like follows:

Machine1 (Dual Core) (XP Home) : Result is : 0.555
Machine2 (Dual Core) (XP Home) : Result is :  0.554
Machine3 (Dual Core) (XP Home) : Result is :  0.554
Machine4 (Dual Core) (XP Home) : Result is :  0.554
Machine5 (Core 2 Duo) (XP Professional) : Result is :  0.554
Machine6 (Core 2 Duo) (Vista Business) : Result is :  0.554
Machine7 (Dual Core) (Vista Basic) : Result is :  0.554

Do you have any explanation why Machine1 gave me the Result (0.555) while other 6 machines gave the result (0.554)?

``````var
R, X, Z : Real;
S, W : String;
begin

R := 1.1085884101;

S := FloatToStrF(R, ffFixed, 15, 3 );

Edit1.Text := S;

X := 0.500;

Z := X * StrToFloat(Edit1.Text);

W := FloatToStrF(Z, ffFixed, 15, 3 );

Edit2.Text := W;

end;
``````
Comment
Watch Question

## View Solutions Only

Commented:
Interesting.

It sounds like a different floating point library is being invoked on the first pc.  I thought that maybe Machine 1 is your development pc, but then maybe not, as it's running Home Edition.

Commented:
there are only two possibilities for the discrepancy here: either the computation is different between the machines, or the computation is the same across all the machines but the conversion (FloatToStr) worked differently.

So to see which this is, I would add more edit boxes that show the same result, but with additional precision. So you can see exactly what is going on.

In addition, perhaps you could also add a different method of conversion, such as using the "format" statement.

R := 1.1085884101;
Edit1.Text := FloatToStrF(R, ffFixed, 15, 3);
Edit3.Text := FloatToStrF(R, ffFixed, 15, 7);  //additional precision here
Edit5.Text := format('%15.7f",[R]);

Z := 0.500 * StrToFloat(Edit1.Text);
Edit2.Text  := FloatToStrF(Z, ffFixed, 15, 3);
Edit4.Text  := FloatToStrF(Z, ffFixed, 15, 7);
Edit6.Text := format('%15.7f",[Z]);

After you get these results, you can narrow down the causes...

Commented:
moorhouselondon: The development pc is Machine7

Commented:
What is the spec of the cpu in m/c 1 compared with the others?

Commented:
It is a Dual Core, like the majority

But Excat model and spec. I will provide them tomorrw , because I am home now. and the machine at my work place.

I will run Everest and provide detailed information for all machines.

Do you think calculating in high level langauges such as delphi depends on CPU?

Then, How large Database Applications (such as Cost calculations) will guarantee  exact results on many machines which has differenet types of processors?

Commented:
JosephGlosz:

Your Code is ready now, But I am home and I will make this Test Tomorrow at work (since all 7 machines are at my work place)

and I will make a screen shot for all PCs and provide them to you.

Commented:
Apparently this is the standard to which floating point implementations should adhere to:-

http://en.wikipedia.org/wiki/IEEE_754

Many years ago Intel had a bug in their Pentium fpu - from recollection I believe some software vendors coded in a method of detecting the flaw and compensate for it.

http://en.wikipedia.org/wiki/Pentium_FDIV_bug

Commented:
Machine7 (buggy machine) spec. :

development machine spec.:

Commented:
I found something STRANGE guys!!!!!!!!!

it is the Value of X

when X = 0.500 , Machine1 Result  (0.555)
All Others Result (0.554)

when X = 1.500 , Machine1 Result  (1.664)
All Others Result (1.663)

when X = 876.500 , Machine1 Result  (972.039)
All Others Result (972.038)
---------------------
when X = 0.200 , Machine1  Result (0.222)
All Others Result (0.222)  SAME!

when X = 1150 , Machine1 Result  (1275.350)
All Others Reslut (1275.350) SAME!

when X = 1.555 , Machine1 Result (1.724)
All Others Reslut (1.724) SAME!

when X = 1.050 , Machine1 Result (1.164)
All Others Reslut (1.164) SAME!

when X = 1.005 , Machine1 Result (1.115)
All Others Reslut (1.115) SAME!

That is mean when X floating point is .500 then the difference happen!

I am confused !!!!!!!!! what the hell with .500 in that machine

Commented:
is int the result before using the FloatToStrF 0.5545 and the precision should be 0.555 not 0.554?

I have the feeling the Machine1 is correct result and others are not !!!

Commented:
oh no

applying ffFixed on 0.5545 will result 0.554 not 0.555

so question cam to the front again, why Machine one result 0.555 !
CERTIFIED EXPERT
Top Expert 2014

Commented:
Are these .Net assemblies or Win32 executables?

The round-up and round-down looks like banker's rounding.

Commented:
I thought the question was more about why the results are different on different pc's, rather than how the result was arrived at.  I'm not complaining btw, just interested to know the outcome as to how the results came to be different :-)  This looks to me like some kind of chipset difference.  Looking at the Everest snapshots of the machines, they are both Intel cpu's, but very different in spec.

Commented:
aikimark: they are Win32.

what do you mean by banker's rounding??

Commented:
moorhouselondon: yes my questions is about why the results are different on different pc's

I show you how the result was arrived at because I want to give you full details and results, many inputs.

It is not that big difference between machines.

how about the operating system? The buggy machine is the only machine runing on XP SP2, all other XP machines are running on XP SP3

Vista machine, SP1 .

all of them are up tp date with microsoft, except the buggy machine,

can we consider this matter? or the OS has nothing to do with it?

CERTIFIED EXPERT
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)

Commented:
Found this too, ok nowhere near Delphi, but relevant nonetheless:-

http://support.microsoft.com/kb/178527

Rather than drop into low level code to reset the fpu, this article suggests a simple workaround.

Commented:
aikimark:
* What version of Delphi is this application?   Delphi 2009

* Is there any difference in the maintenance levels for these systems? no

* Are there any Regional Settings differences between Machine1 and the other PCs? I checked them all, no difference

I will try using Double instead of Real and inform you the result.

Thanks for the links, very useful

Commented:
moorhouselondon: much appreciate your kind interest.

I will read these articles carefuly and then give you my feedback and I hope we can solve this problem.

But I suggest for myself to update Machine1 first for the latest windows updates and then try, if problem solved then it is something related to OS, otherwise... hmmm .. I don't know

let me read articles and understand ur point of view

it is almost 12:30 am now, so sleepy, Tomorrow will continue...

Thanks alot guys

CERTIFIED EXPERT
Top Expert 2014

Commented:
I looked at the first moorhouselondon link.  Given the currency of the hardware (dual core and 2 core dual) and the lessons learned from the  Pentium II debacle, I don't think the FPU (hardware) is suspect.

Commented:
Yes I think a lot was learned from the Pentium II prob - but there's new hardware, new ways to prod it.  Could be a glitch in the way it is being prodded, which is alluded to in other links.
CERTIFIED EXPERT
Top Expert 2014

Commented:

What did you do to make Machine1 results the same as the other systems?

Commented:

aikimark: just updated the windows to SP3.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
###### Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Connect with Certified Experts to gain insight and support on specific technology challenges including:

• Troubleshooting
• Research
• Professional Opinions
Unlock the solution to this question.

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.