home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / pascal / 8019 < prev    next >
Encoding:
Text File  |  1993-01-10  |  1.8 KB  |  63 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!email!ps1.iaee.tuwien.ac.at!Sorokin
  3. From: Sorokin@ps1.iaee.tuwien.ac.at (Sorokin Zhenya)
  4. Subject: Re: TP 6.0 Strange rounding problem (Debugger is *lying* to me!)
  5. Message-ID: <Sorokin.57.726713348@ps1.iaee.tuwien.ac.at>
  6. Lines: 49
  7. Sender: news@email.tuwien.ac.at
  8. Nntp-Posting-Host: pc77.iaee.tuwien.ac.at
  9. Organization: Inst. of General Electronics and Electroengeneering, TU Vienna
  10. 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>
  11. Date: Mon, 11 Jan 1993 00:49:08 GMT
  12. Lines: 49
  13.  
  14.  
  15. I've found finally how the rounding is being controlled in 87.
  16. Below is a test program which is self-explanatory. 
  17.  
  18. -------------------------
  19.  
  20. program 87_Rounding_Test;
  21. { Sorokin E.V., 1993}
  22.  
  23. {Bits 10,11 of 8087 control word are encountered}
  24. const r00 = 0 shl 10; {bank rounding : to the nearset integer if .5}
  25.       r01 = 1 shl 10; {down if .5}
  26.       r10 = 2 shl 10; {up if .5}
  27.       r11 = 3 shl 10; {truncate to integer}
  28.       blank = not word(r11);
  29.  
  30. var cw : word;
  31.     x:double;
  32. begin
  33.   
  34.   asm
  35.     fstcw cw         {We take control word and change it. If you are sure,
  36.                       what it should be, you may simply load proper one
  37.                       using only fldcw directive}
  38.     and cw,blank
  39.     or  cw, r10      {change to r00,r01,r11 to test}
  40.     fldcw cw
  41.   end;
  42.  
  43.   x:= 513.5;
  44.   writeln( round(x));
  45. end.
  46.  
  47. --------------
  48.  
  49. This doesn't answer why TP acted not according to documentation.
  50.  
  51. I also suspect that Truncate procedure may change the settings.
  52.  
  53. You are free to use this code at any point within your program, because it 
  54. doesn't interact with internal 87 stack and status word.
  55.  
  56. Suppose this solves a problem.
  57.  
  58. Sincerely,
  59. Sorokin Zhenya
  60. Vienna, Austria.
  61.  
  62.  
  63.