If you want to rearrange the code to be more Delphi-like, try something like the following (untested):
[pascal]function MungeFPCW(out pwOldCW: Word): Boolean;
var
wSave: Word;
begin
Result := False;
wSave := Default8087CW;
pwOldCW := wSave;
if ((wSave and $300) <> 0) or // Not single mode
($3f <> (wSave and $3f)) or // Exceptions enabled
((wSave and $C00) <> 0) then // Not round to nearest mode
begin
wSave := wSave and not $300; // single mode
wSave := wSave or $3f; // disable all exceptions
wSave := wSave and not $C00; // round to nearest mode
Set8087CW(wSave);
Result := True;
end;
end;
var
Old8087: Word;
initialization
MungeFPCW(Old8087);
finalization
Set8087CW(Old8087);
end.[/pascal]
No idea whether the above clearer code works - let me know please!
Note that it's also the programmer's responsibility to restore the CW at the end...
Bookmarks