Article View: comp.lang.postscript
Article #831Bug in PostScript math
From: Craig Werner
Date: Thu, 10 Aug 1989 01:40
Date: Thu, 10 Aug 1989 01:40
65 lines
2371 bytes
2371 bytes
I recently encountered a problem that seems to be do to a bug in
the PostScript arithmetic routines built into an Apple LaserWriter IINT.
Consider the following:
1) divide 200 by 5, save the 40 in a variable
2) add 200, later subtract 200
3) divide the variable byt the current value, the answer is 1.0
4) truncate the 1.0, the answer should still be 1.0.
Now divide 200 by 3, saving 66.6667.
When you truncate the 1.0 in step 4, the result is 0.0
If you don't believe me, run the following code fragment with the variable
"nlines" (~4 lines from the bottom) set to either 5 or 3.
Please note, however, that since the truncation is
necessary in the logic of the loop, the bug causes an
infinite loop. All the functionality of the following routine has been
removed, only the logic and debugging statements remain.
%!PS
/inch {72 mul} def
/str 11 string def
/DEBUG { dup str cvs show ( ) show } def
/Times-Roman findfont 8 scalefont setfont
/COUNTER 0 def
1 inch 10 inch COUNTER 10 mul sub moveto
/linMSEG
{
MZeroPoint sub /_finish exch def
MZeroPoint sub /_start exch def
_start DEBUG dup linelimit div DEBUG truncate DEBUG dup /Line exch def
linelimit mul sub
DEBUG /rstart exch def
_finish Line linelimit mul sub
DEBUG /rfinish exch def
/COUNTER COUNTER 1 add def
1 inch 10 inch COUNTER 10 mul sub moveto
copypage
rfinish linelimit le
{}
{ Line 1 add linelimit mul MZeroPoint add _finish MZeroPoint add linMSEG
} ifelse
} def
/COUNTER 0 def
/start 200 def
/finish 400 def
/length finish start sub def
/nlines 3 def
/MZeroPoint 200 def
/linelimit length nlines div def
start finish linMSEG
--
Craig Werner (future MD/PhD, 4.5 years down, 2.5 to go)
werner@aecom.YU.EDU -- Albert Einstein College of Medicine
(1935-14E Eastchester Rd., Bronx NY 10461, 212-931-2517)
"If it weren't for politicians, who would fashion disorder out of chaos."
Technical Details
Message-ID:
<2395@aecom.yu.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!aecom!wernerShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!watmath!att!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!aecom!werner From: werner@aecom.yu.edu (Craig Werner) Newsgroups: comp.lang.postscript Subject: Bug in PostScript math Keywords: 200/3 Message-ID: <2395@aecom.yu.edu> Date: 10 Aug 89 01:40:19 GMT Distribution: na Organization: Albert Einstein Coll. of Med., NY Lines: 65