Numbers & Delphi


    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)?

  R, X, Z : Real;
  S, W : String;
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;

Open in new window

Who is Participating?

Improve company productivity with a Business Account.Sign Up

aikimarkConnect With a Mentor Commented:
Banker's Rounding is also known as Gaussian rounding.

Some functions in Delphi employ this, such as the Round() function:


Nice floating point explanation including conversions:

* What version of Delphi is this application?
* Is there any difference in the maintenance levels for these systems?
* Are there any Regional Settings differences between Machine1 and the other PCs?

Since Real is obsolete, try using Double as the data type.  see snippet

  R, X, Z : Double;

Open in new window


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.
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.  

So for example, do this instead of your code:

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...

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

i7madAuthor Commented:
moorhouselondon: The development pc is Machine7
What is the spec of the cpu in m/c 1 compared with the others?
i7madAuthor 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?
i7madAuthor Commented:

  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.
Apparently this is the standard to which floating point implementations should adhere to:-

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.
i7madAuthor Commented:
Machine7 (buggy machine) spec. :

development machine spec.:
i7madAuthor 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

i7madAuthor 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 !!!
i7madAuthor 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 !
Are these .Net assemblies or Win32 executables?

The round-up and round-down looks like banker's rounding.
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.
i7madAuthor Commented:
aikimark: they are Win32.

what do you mean by banker's rounding??
i7madAuthor 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?

moorhouselondonConnect With a Mentor Commented:
This link:-

see the section which starts:-

Preserving registers

Delphi uses the same register preserving conventions as R, so this is mostly done automatically. The only problem that is likely to arise is with the floating point processor (FPU) registers. Some versions of Delphi change the FPU control word upon entry to a DLL (but this is not true of Delphi 5); all Windows programs are at risk of changing the registers whenever they call a sloppily written DLL, such as the ones that are used in the common dialogs (File Open, etc.).

To protect against messing up R by changing the FPU control word, the following strategy works:


Ok the article is quite old, but it points the finger at DLL's that do not correctly initialise the FPU.  The facts are probably that you are running this test with nothing else of consequence running, and you would get inconsistent answers on different occasions if that were not the case - so it looks to me like a DLL your program calls is a different version on Machine 1.  Quite likely if this is SP2 and the rest are SP3  The sure-fire way to determine this is to visit and download something from there.  I'll just have a look at the site and will report back in a few mins.
Found this too, ok nowhere near Delphi, but relevant nonetheless:-

Rather than drop into low level code to reset the fpu, this article suggests a simple workaround.
i7madAuthor Commented:
* 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
i7madAuthor 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

much appreciate your kind efforts.
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.
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.

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

aikimark: just updated the windows to SP3.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.