🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #2025

Re: Overloading?

#2025
From: Ben Stuyts
Date: Sat, 27 Apr 1991 07:01
43 lines
1914 bytes
 GE> Whenever I've written fixed point routines, I've always scaled
 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.

Furthermore, I think my original solution is more readable:

  fix3 := Mul(fix1, fix2);

Althoug, again, operator overloading would make the even nicer:

  fix3 := fix1 * fix2;

The same problem obviously applies to division and also to other
representations for fixed point numbers like +/-.15 bit.

Best regards,
Ben


--  
uucp: uunet!m2xenix!puddle!2!281!202.6!Ben.Stuyts
Internet: Ben.Stuyts@p6.f202.n281.z2.fidonet.org
Technical Details
Message-ID: <1860.281C3565@puddle.fidonet.org>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!cs.uoregon.edu!ogicse!qiclab!percy!m2xenix!puddle!p6.f202.n281.z2.fidonet.org!Ben.Stuyts

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!cs.uoregon.edu!ogicse!qiclab!percy!m2xenix!puddle!p6.f202.n281.z2.fidonet.org!Ben.Stuyts
From: Ben.Stuyts@p6.f202.n281.z2.fidonet.org (Ben Stuyts)
Newsgroups: comp.lang.modula2
Subject: Re: Overloading?
Message-ID: <1860.281C3565@puddle.fidonet.org>
Date: 27 Apr 91 07:01:36 GMT
Sender: ufgate@puddle.fidonet.org (newsout1.26)
Organization: FidoNet node 2:281/202.6 - ST Quick BBS Haarle, Haarlem Holland
Lines: 43