Heading:qjk40(635)Mesa 6 Floating Pointy756qjk40Page Numbers: Yes  X: 527  Y: 10.5"qjk40Inter-Office Memorandumz18592l4445y762\f5bTo	Mesa Floating Point Users	Date	November 4, 1980z18592l4445d2998e21(0,65535)(1,4445)(5,11684)(6,14146)\f1 2f0 27f1 4f0From	Larry Stewart	Location	Palo Altoz18592l4445d2998y716e25\f1 4f0 15f1 8f0Subject	Mesa 6 Floating Point Package	Organization	CSLz18592l4445d2998e25\f1 7f0 31f1 12f0z18592l4445XEROX       z18592l508y644e14(2116)\f2 5f0Filed on: [Ivy]<CedarLib>Real>MesaFloat60.bravo, .presse30e10This memo describes the Floating Point package for Mesa 6.e12jk40Compatibilitye12jk40\b13BThere have been many changes from the Mesa 5 floating point.  In particular, the number format has changed to conform to the proposed IEEE floating point standard, the floating point definitions files have all changed, and compiler support is considerably different.e12jk40\134f1 4f0Distribution and supporte12jk40\b24BFor users within PARC/CSL, this package resides on [Ivy]<CedarLib>Real>.  Messages about floating point should be directed to [Ivy]<CedarLib>Real>Support.dl.  Users of the package should request (by sending a message to Support.dl) to be added to [Ivy]<CedarLib>Real>Users.dl.e12jk40There are various test programs available for floating point.  If you need help, send a message to Support.dl, as above.e12jk40Number Formate12jk40\b13BA Mesa REAL is a 32 bit floating point number consisting of a sign bit, 8-bit excess 127 exponent, hidden bit, and 23 bit mantissa with interpretation as the fraction part of a number between 1 and 2.  Mesa REALs conform to the proposed IEEE standard [1].e12jk40\7f1 4f0 196f1 5f0 25f1 4f0Major features of the proposal are:e12jk40Careful specification of formats and arithmetic operations.l4269e6jk40Careful specification of conversion to and from Decimal.l4269e6jk40Gradual underflow, which reduces the bad effects of underflow.l4269e6jk40Not-A-Numbers, distinguished bit patterns which either trap or propagate unchanged through operations.l4269e6jk40Client settable rounding mode, exceptions individually maskable, "sticky" exception flags.l4269e6jk40The Mesa implementation of IEEE floating point provides fixed modes for handling of rounding, denormalized numbers, and infinity.  The implementation also enables a fixed set of exceptions.  An optional interface provides variable modes for access to the full generality of the standard.e12jk40\27f1 4f0New language supporte12jk40\b20BThe Mesa 6 Compiler provides the type REAL, and generates code for evaluation of expressions involving the operations on REALs +, -, *, /, _, Float (conversion from LONG INTEGER to REAL, a widening automatically supplied by the compiler), and compare (=, #, <, <=, >=, >).  In addition, the Mesa 6 compiler supports REAL literals, REAL intervals, and the unary operations - (negation) and ABS [2].  The Mesa 6 debugger will print REALs without any added modules.e12jk40\38f1 4f0 79f1 5f0 39f1 12f0 4f1 55f0 80f1 4f0 11f1 4f0 54f1 3f0 38f1 5f0The Mesa 6 debugger will print REAL types correctly, but cannot handle REAL expressions or assign to a REAL.e12jk40\31f1 4f0 36f1 4f0 28f1 4f0About the implementatione12jk40\b24BThe Mesa compiler generates instructions for the operations mentioned above.  Additional operations (Fix, Round) are declared as MACHINE CODE, they generate instructions as well.  Because microcode support is required, Mesa 6 floating point will not work on the Alto I or on Alto IIs with version 39 or earlier Mesa ROMs.  The Alto II, D0, and Dorado all use different microcode, but the supporting mesa package is the same, hence it is possible to run the same compiled code on all machines.  There is a compiler switch (/f, /-f) for floating point.  It should be used as /f or just left off altogether.e12jk40\129f1 12f0Floating point microcode for the Alto II is supplied by the Mesa 6 version of RunMesa.run.  Floating point microcode for the Dorado is included in the standard Cedar microcode release.  Floating point microcode for the D0 and Dolphin should be available from your support organization.e12jk40Available Interfacese12jk40\b20BThe interface Real provides the basic facilities needed by most users of floating point.  Additional numerical functions are provided by RealFns.  The interface RealOps supplies the same operations as Real, but with all the modes explicit,  giving the full generality of the IEEE standard.  RealConvert supplies some procedures for conversion of Mesa 6 REALs to and from other formats.  Ieee supplies access to internal details of floating point numbers.  Some of these facilities are described below.  Users should look at the definitions files in case of any uncertainty; they represent the truth.e12jk40\14i4I119i7I17i7I107f1 4f0 12i11I51f1 4f0 30i4IWhat you neede12jk40\b13BReal, RealFns, RealOps, and Ieee are implemented by the configuration RealImpl.bcd; RealConvert is implemented by the module RealConvertImpl.  You may wish to have RealImpl.symbols around in case you get any exceptions.e12jk40The most common pitfallse12jk40\b24BDon't forget to load and START RealImpl.  You may get along fine for a while because most operations are in microcode, but "hard" operations and operands are handled by the supporting Mesa code, which must be there!  The symptom will probably be a ControlFault or StackError.e12jk40\25f1 5f0Have the right microcode on your D0 or Dolphine12jk40Don't try to use REALs on an Alto I or Alto II with old Mesa ROMs.e12jk40Don't forget to request to be added to the Users distribution list.  The maintainers are unlikely to be sympathetic if you hit an already fixed bug.e12jk40in Real (exported by RealImpl)e12jk40\b30BThe configuration RealImpl.bcd IMPORTS StringDefs and EXPORTS Real, RealFns, Ieee, and RealOps.  RealImpl also IMPORTS InlineDefs, but inline procedures only.e12jk40\31f1 8f0 15f1 7f0 50f1 7f0InitReals: PROCEDURE;e12jk40\f6 9f7RealControl: PROGRAM;e6jk40\f6 11f7InitReals must be called or RealControl STARTed before any floating point operations are executed (including any initialization other than REAL literals which occur in a global frame containing a call to InitReals).  It is ok to call InitReals more than once.  Fine points: STARTing the configuration RealImpl by including it on the command line is good enough.  There should not be any need to call InitReals on return from a MakeImage.l4269e6jk40\40f1 7f0 92f1 4f0 71i1I46f1 176f0Exceptionsl3658d2998e12(1792)\i10IFlag: TYPE = BOOLEAN _ FALSE;l3658d2998e12\f7Exception: TYPE = {fixOverflow, inexactResult, invalidOperation, divisionByZero, overflow, underflow};l3658d2998e6\f7ExceptionFlags: TYPE = PACKED ARRAY Exception OF Flag;l3658d2998e6\f7UsualExceptions: ExceptionFlags = [fixOverflow: TRUE, invalidOperation: TRUE, divisionByZero: TRUE, overflow: TRUE];l3658d2998e6\f7RealException: SIGNAL [flags: ExceptionFlags, vp: POINTER TO Extended] RETURNS [POINTER TO Extended];l3658d2998e12\f6b13f7BPOINTER above will be replaced by REF for Cedar Mesa.l4269e6jk40(2116)\f1 7f0 27f1 3f0 15f1 1f0RealError: ERROR;l3658d2998e6(1792)\f6b9f7BRealException is raised whenever an enabled exception occurs.  The parameter flags indicates which exceptions occurred during the faulted operation (including any which occurred but were not enabled).  For operations called through the interface Real (or by the Mesa compiler), the only enabled exceptions are those listed under UsualExceptions above.  Usually a catch phrase for RealException can RESUME.  The client is expected to fix up the initial result represented by vp, then return the new value to use as the result of the faulted operation.  If the client returns NIL, a default result specified by the IEEE standard will be used.l4269e6jk40(2116)\60i1I16f6 5f0 316f1 6f0 70f6 2f0 98f1 3f0 36f1 4f0The exception invalidOperation when raised as a result of compare or any of the real to fixed point conversion operations is not resumable.  If the client RESUMEs anyway, the ERROR RealError will be raised.l4269e12jk40\155f1 7f0 13f1 5f0Fine point: because of the way SIGNAL catching is implemented, a catch phrase on a MACHINE CODE procedure (such as Fix or Round) or a catch phrase on a block enclosing floating point operations will not work; however, a catch phrase at least one procedure call removed from a floating point operation will work.l4269e12jk40\f1 311f0Clients wishing to test for uninitialized storage of REAL types may wish to set that storage to the value Real.TrappingNaN.  This distinguished operand will produce a SIGNAL if it is ever picked up as an operand of a floating point operation (other than assignment).e12jk40\53f1 4f0 110f1 6f0Default results of exceptional conditionse12jk40\ifixOverflow:  returns least significant bits of the correct result.l4269e6jk40inexactResult:  returns rounded version of preliminary resultl4269jk40invalidOperation:  returns Not-a-Number characteristic of the faulted operation.l5327d4269jk40divisionByZero:  returns Not-a-Number DivideInfinityNaN.l5327d4269jk40overflow:  returns infinity of the correct sign.l4269jk40underFlow:  returns de-normalized number.l4269jk40Conversion operationse12jk40\iFix: PROCEDURE [REAL] RETURNS [LONG INTEGER];e6(1792)\f6b3f7BFixI: PROCEDURE [REAL] RETURNS [INTEGER];e6\f6b4f7BFixC: PROCEDURE [REAL] RETURNS [CARDINAL];e6\f6b4f7BRoundLI: PROCEDURE [REAL] RETURNS [LONG INTEGER];l3658d2998e6\f6b7f7BRoundI: PROCEDURE [REAL] RETURNS [INTEGER];l3658d2998e6\f6b6f7BRoundC: PROCEDURE [REAL] RETURNS [CARDINAL];l3658d2998e6\f6b6f7BThe Fix operations use rounding mode round-to-zero (truncation).  The Round operations use mode round-to-nearest  These operations can raise exceptions such as fixOverflow or invalidOperation.l4269e6jk40(2116)Float: PROCEDURE [LONG INTEGER] RETURNS [REAL];e12(1792)\f6b5f7BFloat is generated automatically by the compiler, but a client may wish to use it explicitly.l4269e6jk40(2116)Input and Outpute12jk40\iReadReal: PROCEDURE [get: PROCEDURE RETURNS[CHARACTER],putback: PROCEDURE[CHARACTER] _ DefaultPutback] RETURNS [REAL];l3658d2998e12(1792)\f6b8f7BStringToReal: PROCEDURE [STRING] RETURNS [REAL];l3658d2998e12\f6b12f7BThe procedures which convert to REAL may generate exceptions depending on the value represented by the input.  ReadReal must read past the end of the number input; it uses putback to return the last character read.  DefaultPutback discards the character.l4269e6jk40(2116)\32f1 4f0 136f6 7f0MaxSinglePrecision: CARDINAL = 9;l3658d2998e12(1792)\f7DefaultSinglePrecision: CARDINAL = 7;l3658d2998\f7WriteReal: PROCEDURE [cp: PROCEDURE[CHARACTER], r: REAL,precision: CARDINAL _ DefaultSinglePrecision, forceE: BOOLEAN _ FALSE];l3658d2998e12\f6b9f7BAppendReal: PROCEDURE [s: STRING, r: REAL,precision: CARDINAL _ DefaultSinglePrecision, forceE: BOOLEAN _ FALSE];l3658d2998e12\f6b10f7BThe procedures which convert from REAL will not generate exceptions.  If forceE is TRUE or the value is not IN [0.000001..1000000) then the number will be printed in scientific notation.  The output value will have precision significant digits.l4269e6jk40(2116)\34f1 4f0 45f1 4f0 21f1 2f0in WFReal (exported by WFRealImpl)e12jk40\b34BThese procedures are intended for use as print procedures in the WriteFormatted package.  See the WriteFormatted package documentation.  WFReal and WFRealImpl are distributed with the WriteFormatted package.l4269e6jk40InitWFReals: PROCEDURE;l3658d2998e12(1792)\f6b11f7B12bWFWriteReal: PROCEDURE [rp: UNSPECIFIED, f: STRING, p: PROCEDURE [CHARACTER]];l3658d2998e12\f6b11f7BWFWriteEReal: PROCEDURE [rp: UNSPECIFIED, f: STRING, p: PROCEDURE [CHARACTER]];l3658d2998e12\f6b12f7Bin RealFns (exported by RealImpl)e12jk40(2116)\b33BExp: PROCEDURE [REAL] RETURNS [REAL];z19402l3633d2999x2e12k72(635)\f6b3f7BFor an input argument n, returns en (e=2.718...).  Computed by continued fractions.z19402l4269x2e12j\34o4 1o0Log: PROCEDURE [base,arg: REAL] RETURNS [REAL];z19402l3633d2999x2e12k72\f6b3f7BComputes logarithm to the base base of arg.  Computed by Ln(arg)/Ln(base).z19402l4269x2e12j\31f6 4f0 4f6 3f0Ln: PROCEDURE [REAL] RETURNS [REAL];z19402l3633d2999x2e12k72\f6b2f7BComputes the natural logarithm (base e) of the input argument.z19402l4269x2e12jSqRt: PROCEDURE [REAL] RETURNS [REAL];z19402l3633d2999x2e12k72\f6b4f7BCalculates the square root of the input value by Newton's iteration.z19402l4269x2e12jRoot: PROCEDURE [index,arg: REAL] RETURNS [REAL];z19402l3633d2999x2e12k72\f6b4f7BCalculates the index root of arg by e(Ln(arg)/index).z19402l4269x2e12j\15f6 5f0 9f6 3f0 5o4 15o0Power: PROCEDURE [base,exponent: REAL] RETURNS [REAL];z19402l3633d2999x2e12k72\f6b5f7BCalculates base to the exponent power by e(exponent*Ln(base)).z19402l4269x2e12j\11f6 4f0 8f6 8f0 11o4 19o0Sin: PROCEDURE [radians: REAL] RETURNS [REAL];z19402l3633d2999x2e12k72\f6b3f7BSinDeg: PROCEDURE [degrees: REAL] RETURNS [REAL];z19402l3633d2999x2e6k72\f6b6f7BCos: PROCEDURE [radians: REAL] RETURNS [REAL];z19402l3633d2999x2e6k72\f6b3f7BCosDeg: PROCEDURE [degrees: REAL] RETURNS [REAL];z19402l3633d2999x2e6k72\f6b6f7BTan: PROCEDURE [radians: REAL] RETURNS [REAL];z19402l3633d2999x2e6k72\f6b3f7BTanDeg: PROCEDURE [degrees: REAL] RETURNS [REAL];z19402l3633d2999x2e6k72\f6b6f7BComputes the trigonometric function by polynomial; good to 7.33 decimal places.z19402l4269x2e12jArcTan: PROCEDURE [y, x: REAL] RETURNS [radians: REAL];z19402l3633d2999x2e12k72\f6b6f7BArcTanDeg: PROCEDURE [y, x: REAL] RETURNS [degrees: REAL];z19402l3633d2999x2e6k72\f6b9f7BGood to 8.7 decimal places.z19402l4269x2e12jAlmostZero: PROC [x: REAL, distance: [-126..127]] RETURNS [BOOLEAN];z19402l3633d2999x2e12k72\f6b10f7BReturns TRUE if ABS[x]<2^distance.z19402l4269x2e12jAlmostEqual: PROC [x, y: REAL, distance: [-126..127]] RETURNS [BOOLEAN];z19402l3633d2999x2e12k72\f6b11f7BReturns TRUE if (ABS[x-y]/MAX[ABS[x],ABS[y]])<2^distance.z19402l4269x2e12jin RealConvert (exported by RealConvertImpl)e12jk40(2116)\b44BThe module RealConvertImpl IMPORTS InlineDefs (inline procedures only).l4269e6jk40\27f1 7f0Mesa5ToIeee: PROC [LONG UNSPECIFIED] RETURNS [REAL];z19402l3633d2999x2e12k72(635)\f6b11f7BConverts a Mesa 5 REAL to an equivalent Mesa 6 REAL.l4269e6jk40(2116)BcplToIeee: PROC [LONG UNSPECIFIED] RETURNS [REAL];z19402l3633d2999x2e12k72(635)\f6b10f7BConverts a Bcpl REAL to an equivalent Mesa 6 REAL.  Bcpl REALs occur in some Press format files.l4269e6jk40(2116)IeeeToBcpl: PROC [REAL] RETURNS [LONG UNSPECIFIED];z19402l3633d2999x2e12k72(635)\f6b10f7BConverts a Mesa 6 REAL to an equivalent Bcpl REAL.  Bcpl REALs occur in some Press format files.  This operation may raise the signal below on impossible conversions.l4269e6jk40(2116)CVError: ERROR;z19402l3633d2999x2e12k72(635)\f6b7f7B2f6 5f7Referencese12jk40(2116)\b10B[1]  "An Implementation Guide to a Proposed Standard for Floating Point Arithmetic", Jerome T. Coonen, Computer Magazine, January, 1980.l4057d2999e12jk40\103i17I[2]  Mesa 6.0 Compiler Update, Ed Satterthwaite, [Iris]<Mesa>Doc>Compiler60.memo, May 22, 1980.l4057d2999e12jk40