home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!email!ps1.iaee.tuwien.ac.at!Sorokin
- From: Sorokin@ps1.iaee.tuwien.ac.at (Sorokin Zhenya)
- Subject: Re: TP 6.0 Strange rounding problem (Debugger is *lying* to me!)
- Message-ID: <Sorokin.57.726713348@ps1.iaee.tuwien.ac.at>
- Lines: 49
- Sender: news@email.tuwien.ac.at
- Nntp-Posting-Host: pc77.iaee.tuwien.ac.at
- Organization: Inst. of General Electronics and Electroengeneering, TU Vienna
- References: <86277@ut-emx.uucp> <Sorokin.50.726427702@ps1.iaee.tuwien.ac.at> <86406@ut-emx.uucp> <Sorokin.54.726675420@ps1.iaee.tuwien.ac.at>
- Date: Mon, 11 Jan 1993 00:49:08 GMT
- Lines: 49
-
-
- I've found finally how the rounding is being controlled in 87.
- Below is a test program which is self-explanatory.
-
- -------------------------
-
- program 87_Rounding_Test;
- { Sorokin E.V., 1993}
-
- {Bits 10,11 of 8087 control word are encountered}
- const r00 = 0 shl 10; {bank rounding : to the nearset integer if .5}
- r01 = 1 shl 10; {down if .5}
- r10 = 2 shl 10; {up if .5}
- r11 = 3 shl 10; {truncate to integer}
- blank = not word(r11);
-
- var cw : word;
- x:double;
- begin
-
- asm
- fstcw cw {We take control word and change it. If you are sure,
- what it should be, you may simply load proper one
- using only fldcw directive}
- and cw,blank
- or cw, r10 {change to r00,r01,r11 to test}
- fldcw cw
- end;
-
- x:= 513.5;
- writeln( round(x));
- end.
-
- --------------
-
- This doesn't answer why TP acted not according to documentation.
-
- I also suspect that Truncate procedure may change the settings.
-
- You are free to use this code at any point within your program, because it
- doesn't interact with internal 87 stack and status word.
-
- Suppose this solves a problem.
-
- Sincerely,
- Sorokin Zhenya
- Vienna, Austria.
-
-
-