Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!umix!uunet!seismo!sundc!pitstop!sun!rayssd!trr From: trr@rayssd.ray.com (Terry R. Raymond) Newsgroups: comp.lang.smalltalk Subject: STV bug in printFraction: Keywords: Smalltalk/V Message-ID: <2175@rayssd.ray.com> Date: 28 Apr 88 15:53:29 GMT Sender: trr@rayssd.ray.com (Terry R. Raymond @ Raytheon Company, Portsmouth RI) Organization: Raytheon Company, Portsmouth RI Lines: 34 I discovered a bug in the STV printFraction method. Notice the results of the following two expressions. The negative result is in error. -14661/6250 printFraction: 3 '-3.654' 14661/6250 printFraction: 3 '2.345' The following is the method with a correction. printFraction: numberFractionDigits "Answer a string, the ASCII representation of the receiver truncated to numberFractionDigits decimal places." | stream fraction integer num | numberFractionDigits < 0 ifTrue: [self error: 'Negative digit count']. stream := WriteStream on: (String new: 16). num := self. self < 0 ifTrue: [ num := self negated. stream nextPut: $- ]. (integer := num // 1) printOn: stream. stream nextPut: $.. fraction := num - integer. integer := 0. numberFractionDigits timesRepeat: [ fraction := (fraction - integer) * 10. (integer := fraction // 1) printOn: stream]. ^stream contents -- Terry Raymond Raytheon Submarine Signal Division; Portsmouth RI; (401)-847-8000 x5597 smart mailer or arpanet: trr@rayssd.ray.com old dumb mailer or uucp: {cbosgd,gatech,ihnp4,linus!raybed2} !rayssd!trr