VOGONS


First post, by OCTAGRAM

User metadata
Rank Newbie
Rank
Newbie

Floating point mystery topic on USENET shows that is seems to be DOSBox issue. DOSBox FPU implementation seems to be a bit different from what TP expects.

I wrote:

Hello! […]
Show full quote

Hello!

I can't get floating point operations working. Try running this in your version of Turbo (Borland) Pascal:

{$N+}
uses CRT;
type Float = Real;

var X, Y, Z : Float;

function TestOK : Boolean;
var R : String;
begin
X := 2.0;
Y := 5.0;
Z := X / Y;
Str(Z : 0 : 3, R);
TestOK := R = '0.400';
end;

var i : Integer;

begin
i := 0;
while TestOK do
begin
i := i + 1;
if i >= 1000 then begin Write('.'); i := 0; end;
if KeyPressed then Break;
end;
WriteLn('Iterations: ', i);
end.

The problem might appear after you have run this program from IDE several times. It doesn't appear when program is being launched from command line. It doesn't appear on the first launch.

During the first several runs everything is OK: 2.0 / 5.0 = 0.400

But then floating point goes wild. 2.0 / 5.0 = 5.00, then NaNs, then another stupid values. I have to keep {$N-,$E+} mode because of this. I tried various versions of BP, the problem seems to be everywhere.

But I can't remember ever having such a problem on a real DOS environment. So I guess this is DOSBox specific problem.

Do you know a cure against it? {$N-,E+} doesn't count. Neither FPC.

Zaphod Beeblebrox wrote:

I cannot duplicate it running the TP 7 IDE (w/RT 200 patch) in CMD.EXE
under XP SP3, but it does happen in DOSBox 0.72 under XP SP3 exaclty
as you describe it.