🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #1617

Re: Binary operations in Modula-2

#1617
From: Larry M. Jordan
Date: Fri, 14 Dec 1990 23:29
31 lines
1241 bytes
The following will work for JPI which supports type
transfer functions (you may have to use VAL in other M2's):

PROCEDURE And(a,b:CARDINAL): CARDINAL;
BEGIN
  RETURN CARDINAL(BITSET(a) * BITSET(b))
END And;

PROCEDURE Or(a,b:CARDINAL): CARDINAL;
BEGIN
  RETURN CARDINAL(BITSET(a) + BITSET(b))
END Or;

PROCEDURE Not(a:CARDINAL): CARDINAL;
BEGIN
  RETURN CARDINAL(BITSET(0) - BITSET(a))
END Not;

PROCEDURE Xor(a,b:CARDINAL): CARDINAL;
BEGIN
  RETURN And(Or(a,b), Not(And(a,b)))
END Xor;


You can, of course, optimize Xor by 'inlining' by hand
the other ops.

This solution requires no recourse to assembly language.


-- Larry
Technical Details
Message-ID: <94575@aerospace.AERO.ORG>
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!lethe!torsqnt!news-server.csri.toronto.edu!rutgers!mcnc!gatech!udel!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!aero!aerospace.aero.org!jordan
References: <1990Dec13.213402.16572@iesd.auc.dk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!telly!lethe!torsqnt!news-server.csri.toronto.edu!rutgers!mcnc!gatech!udel!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!aero!aerospace.aero.org!jordan
From: jordan@aerospace.aero.org (Larry M. Jordan)
Newsgroups: comp.lang.modula2
Subject: Re: Binary operations in Modula-2
Keywords: Binary
Message-ID: <94575@aerospace.AERO.ORG>
Date: 14 Dec 90 23:29:08 GMT
References: <1990Dec13.213402.16572@iesd.auc.dk>
Sender: news@aerospace.aero.org
Reply-To: jordan@antares.UUCP (Larry M. Jordan)
Organization: The Aerospace Corporation, El Segundo, CA
Lines: 31