Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!cs.uoregon.edu!ogicse!pdxgate!parsely!percy!m2xenix!george From: george@m2xenix.psg.com (George Emery) Newsgroups: comp.lang.modula2 Subject: Re: Overloading? Message-ID: <1991Apr29.194934.18215@m2xenix.psg.com> Date: 29 Apr 91 19:49:34 GMT References: <1860.281C3565@puddle.fidonet.org> Organization: Pacific Systems Group, Portland Oregon US Lines: 47 Ben Stuyts writes: > GE> INTEGERS and LONGINTs when printing. The advantage is that you can > GE> still use +, -, *, / in the normal fashion. You then merely need to > GE> remember to use the correct i/o routines. [Perhaps this is a good > GE> example of why we shouldn't have standard i/o packages?] > >Well, this won't work in all cases, and that's why I've started to >encapsulate the fixed point routines in a separate module. Suppose that >one uses a +/- 7.8 bit representation for a fixed point number. In this >case, the fixed point number 1.0 will be represented by the 16 bit >integer 256. Now we want to multiply 1.0 times 1.0. One could write this >as: > > fix1 := 256; > fix2 := 256; > > fix3 := (LONG(fix1) * LONG(fix2)) DIV 256; > >You cannot simply use (assuming you have 16-bit INTEGERs): > > fix3 := (fix1 * fix2) DIV 256; > >as this would cause an overflow during the multiplication. So then you'd use LONGINT... Actually, I'm a little confused about each other's intentions. For fixed point, I was thinking of scaling for decimal representation, not binary as your example implies. I agree, however, that it sometimes is inconvenient to not have customary operators available. On the other hand, it is seldom, with simple numeric representations, necessary to go outside of what is already provided by the language. >The same problem obviously applies to division and also to other >representations for fixed point numbers like +/-.15 bit. Again, I think we're thinking of different ideas here. My understanding of fixed point numbers is that if you're trying to divide by a fraction of a bit, then you've picked the wrong range or you must represent the fraction-of-a-bit as a continued fraction approximation. Could you enlighten me? george@m2xenix.psg.com