Board index » delphi » Floating Point Errors in DLL's

Floating Point Errors in DLL's

Scenario:

We have a main menu executable which dynamically loads DLLs based on the
menu selection.  These DLLs contain multiple forms and processing
functions. (Avg. size is 550k)

Problem:

We are experiencing unpredictable results with floating point numbers.
The following code segment is one example of the difficulties we are
encountering:

--------------------------------------------------------------------------
--------------------
var
   X: real;
   S: string;

Begin

S := 25.01;
X := StrToFloat(S);
ShowMessage (FloatToStr(X));

end;
The result of the show message is 100 if run on a 486-33sx.
The result of the show message is 25.01 if run on a 486-66dx.
The same applies regardless of the machine it is compiled on.
--------------------------------------------------------------------------
--------------------
var
   X: real;
   S: string;

Begin

S := 25.01;
X := StrToFloat(S);

end;
We receive an exception error Invalid floating point value 25.01.
This only occurs once while the Main EXE remains loaded.
This error does not seem to be machine dependent.
--------------------------------------------------------------------------
--------------------

By reducing the size of the DLL we can eliminate the above errors.
We believe it is a math coprocessor issue, but, that is only a guess.  Any
information or suggestions would be GREATLY appreciated.

Don Taylor

 

Re:Floating Point Errors in DLL's


Scenario:

We have a main menu executable which dynamically loads DLLs based on the
menu selection.  These DLLs contain multiple forms and processing
functions. (Avg. size is 550k)

Problem:

We are experiencing unpredictable results with floating point numbers.
The following code segment is one example of the difficulties we are
encountering:

--------------------------------------------------------------------------
--------------------
var
   X: real;
   S: string;

Begin

S := 25.01;
X := StrToFloat(S);
ShowMessage (FloatToStr(X));

end;
The result of the show message is 100 if run on a 486-33sx.
The result of the show message is 25.01 if run on a 486-66dx.
The same applies regardless of the machine it is compiled on.
--------------------------------------------------------------------------
--------------------
var
   X: real;
   S: string;

Begin

S := 25.01;
X := StrToFloat(S);

end;
We receive an exception error Invalid floating point value 25.01.
This only occurs once while the Main EXE remains loaded.
This error does not seem to be machine dependent.
--------------------------------------------------------------------------
--------------------

By reducing the size of the DLL we can eliminate the above errors.
We believe it is a math coprocessor issue, but, that is only a guess.  Any
information or suggestions would be GREATLY appreciated.

Don Taylor

Re:Floating Point Errors in DLL's


This is an untried shot in the dark but look at the {N+} compiler option,
and/or declaring the real as a single or double.

Re:Floating Point Errors in DLL's


Quote
dont...@aol.com (DONTCFS) wrote:
>Scenario:
>We have a main menu executable which dynamically loads DLLs based on the
>menu selection.  These DLLs contain multiple forms and processing
>functions. (Avg. size is 550k)
>Problem:
>We are experiencing unpredictable results with floating point numbers.
>The following code segment is one example of the difficulties we are
>encountering:
>--------------------------------------------------------------------------
>--------------------
>var
>   X: real;
>   S: string;
>Begin
>S := 25.01;
>X := StrToFloat(S);
>ShowMessage (FloatToStr(X));
>end;
>The result of the show message is 100 if run on a 486-33sx.
>The result of the show message is 25.01 if run on a 486-66dx.
>The same applies regardless of the machine it is compiled on.
>--------------------------------------------------------------------------
>--------------------
>var
>   X: real;
>   S: string;
>Begin
>S := 25.01;
>X := StrToFloat(S);
>end;
>We receive an exception error Invalid floating point value 25.01.
>This only occurs once while the Main EXE remains loaded.
>This error does not seem to be machine dependent.
>--------------------------------------------------------------------------
>--------------------
>By reducing the size of the DLL we can eliminate the above errors.

How do you reduce the DLL size? Could it have the kind of bug that
makes code stab itself in a different place depending on how you
compile it, and that reducing size makes for a lucky painless stab?

Quote
>We believe it is a math coprocessor issue, but, that is only a guess.  Any
>information or suggestions would be GREATLY appreciated.

How would the math processor be affected by DLL size?

Quote
>Don Taylor

(1) Did you try to compile the above? I just pasted it, and it
immediately complained about the '25.01' because it didn't
look like the one I just typed. I.e., your quotes look like
acute accents. Led me to wonder if you are getting numbers as
strings including acute quotes as part of the text from somewhere,
and passing it all into the conversion routine.

(2) Just a guess, but try double instead of real and see if
symptoms change.

(3) Passing floating point parameters in and out of DLLs can
be troublesome too. If you're doing that, are declarations on
both sides really (no pun) matched?

HTH. Regards, Bengt Richter

Re:Floating Point Errors in DLL's


On 26 Jan 1996 18:51:39 -0500, dont...@aol.com (DONTCFS) wrote:

Quote
>We have a main menu executable which dynamically loads DLLs based on the
>menu selection.  These DLLs contain multiple forms and processing
>functions. (Avg. size is 550k)

>Problem:

>We are experiencing unpredictable results with floating point numbers.
>The following code segment is one example of the difficulties we are
>encountering:

There is a known bug in FFMT.ASM, for which there is no workaround if
you do not have the source code. I don't know if this is your problem
or not. The bug can cause unpredictable behavior when converting a
string to a floating point value. Here is a posting from Steve
Teixeira of Borland:

Quote
>The problem is that the TextToFloat procedure (found in FFMT.ASM,
>if you have the VCL Source) tries to access a global variable with the
>app's DSeg loaded rather than the DLL's DSeg.  If you have the source,
>you can work-around this problem by inserting a POP DS instruction
>immediately prior to the call to Power10 in the TextToFloat proc.  You
>must also remove the POP DS instruction found immediately prior to
>the @@8: label in TextToFloat.  I'm afraid there is currently no
>work-around if you don't have the VCL source.

>     -Steve Teixeira
>      steix...@borland.com

--
Ray Lischner         (li...@tempest-sw.com)
Tempest Software, Corvallis, Oregon, USA

Other Threads