Inter-Office MemorandumToMesa Floating Point UsersDateNovember 4, 1980FromLarry StewartLocationPalo AltoSubjectMesa 6 Floating Point PackageOrganizationCSLXEROX Filed on: [Ivy]Real>MesaFloat60.bravo, .pressThis memo describes the Floating Point package for Mesa 6.CompatibilityThere have been many changes from the Mesa 5 floating point. In particular, the number formathas changed to conform to the proposed IEEE floating point standard, the floating point definitionsfiles have all changed, and compiler support is considerably different.Distribution and supportFor users within PARC/CSL, this package resides on [Ivy]Real>. Messages aboutfloating point should be directed to [Ivy]Real>Support.dl. Users of the packageshould request (by sending a message to Support.dl) to be added to[Ivy]Real>Users.dl.There are various test programs available for floating point. If you need help, send a message toSupport.dl, as above.Number FormatA 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 and2. Mesa REALs conform to the proposed IEEE standard [1].Major features of the proposal are:Careful specification of formats and arithmetic operations.Careful specification of conversion to and from Decimal.Gradual underflow, which reduces the bad effects of underflow.Not-A-Numbers, distinguished bit patterns which either trap or propagate unchangedthrough operations.Client settable rounding mode, exceptions individually maskable, "sticky" exception flags.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. Anoptional interface provides variable modes for access to the full generality of the standard.]gp c8q]r-q7Br ]q]r -q7Br Yq]r-q 7BrSsr M7 G: Dt ArW @ qr8 >G ;et 89r'1 6!9 51P$Q 3 0L . +t (rqr-* '#T %qrqr "s# ;8l>H 9)1  qr4 ` 8%=ZDMesa 6 Floating Point2New language supportThe Mesa 6 Compiler provides the type REAL, and generates code for evaluation of expressionsinvolving the operations on REALs +, -, *, /, _, Float (conversion from LONG INTEGER to REAL, awidening automatically supplied by the compiler), and compare (=, #, <, <=, >=, >). In addition, theMesa 6 compiler supports REAL literals, REAL intervals, and the unary operations - (negation) andABS [2]. The Mesa 6 debugger will print REALs without any added modules.The Mesa 6 debugger will print REAL types correctly, but cannot handle REAL expressions or assignto a REAL.About the implementationThe Mesa compiler generates instructions for the operations mentioned above. Additionaloperations (Fix, Round) are declared as MACHINE CODE, they generate instructions as well. Becausemicrocode support is required, Mesa 6 floating point will not work on the Alto I or on Alto IIs withversion 39 or earlier Mesa ROMs. The Alto II, D0, and Dorado all use different microcode, butthe supporting mesa package is the same, hence it is possible to run the same compiled code on allmachines. There is a compiler switch (/f, /-f) for floating point. It should be used as /f or just leftoff altogether.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 supportorganization.Available InterfacesThe interface Real provides the basic facilities needed by most users of floating point. Additionalnumerical functions are provided by RealFns. The interface RealOps supplies the same operationsas 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 aredescribed below. Users should look at the definitions files in case of any uncertainty; theyrepresent the truth.What you needReal, RealFns, RealOps, and Ieee are implemented by the configuration RealImpl.bcd; RealConvertis implemented by the module RealConvertImpl. You may wish to have RealImpl.symbols aroundin case you get any exceptions.The most common pitfallsDon't forget to load and START RealImpl. You may get along fine for a while because mostoperations are in microcode, but "hard" operations and operands are handled by the supportingMesa code, which must be there! The symptom will probably be a ControlFault or StackError.Have the right microcode on your D0 or DolphinDon't try to use REALs on an Alto I or Alto II with old Mesa ROMs.Don't forget to request to be added to the Users distribution list. The maintainers are unlikely tobe sympathetic if you hit an already fixed bug.in Real (exported by RealImpl) frG bt ^rqr2 ]nqr q rq [r6 Zfqr qr& Xqr&qr Uqr$qr T3qr Qt Mr,, LX'q r. JI IP!= GG FHQ D A(2 @D >  9 = 9t 6r ur4 51$urur 3*#qr 2)u r( qr 0ur$9 /!G - *rt 'Fr$; %6% $> !t r qr; cN ; . B ]#A / t x g>[IMesa 6 Floating Point3The configuration RealImpl.bcd IMPORTS StringDefs and EXPORTS Real, RealFns, Ieee, andRealOps. RealImpl also IMPORTS InlineDefs, but inline procedures only.InitReals: PROCEDURE;RealControl: PROGRAM;InitReals must be called or RealControl STARTed before any floating point operations areexecuted (including any initialization other than REAL literals which occur in a global framecontaining 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 notbe any need to call InitReals on return from a MakeImage.ExceptionsFlag: TYPE = BOOLEAN _ FALSE;Exception: TYPE = {fixOverflow, inexactResult, invalidOperation, divisionByZero, overflow, underflow};ExceptionFlags: TYPE = PACKED ARRAY Exception OF Flag;UsualExceptions: ExceptionFlags = [fixOverflow: TRUE, invalidOperation: TRUE, divisionByZero: TRUE,overflow: TRUE];RealException: SIGNAL [flags: ExceptionFlags, vp: POINTER TO Extended] RETURNS [POINTER TOExtended];POINTER above will be replaced by REF for Cedar Mesa.RealError: ERROR;RealException is raised whenever an enabled exception occurs. The parameter flagsindicates which exceptions occurred during the faulted operation (including any whichoccurred but were not enabled). For operations called through the interface Real (or by theMesa 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 theinitial result represented by vp, then return the new value to use as the result of the faultedoperation. If the client returns NIL, a default result specified by the IEEE standard will beused.The exception invalidOperation when raised as a result of compare or any of the real tofixed point conversion operations is not resumable. If the client RESUMEs anyway, theERROR RealError will be raised.Fine point: because of the way SIGNAL catching is implemented, a catch phrase on a MACHINE CODEprocedure (such as Fix or Round) or a catch phrase on a block enclosing floating point operations will notwork; however, a catch phrase at least one procedure call removed from a floating point operation will work.Clients wishing to test for uninitialized storage of REAL types may wish to set that storage to thevalue Real.TrappingNaN. This distinguished operand will produce a SIGNAL if it is ever picked upas an operand of a floating point operation (other than assignment).Default results of exceptional conditionsfixOverflow: returns least significant bits of the correct result.inexactResult: returns rounded version of preliminary resultinvalidOperation: returns Not-a-Number characteristic of the faulted operation.divisionByZero: returns Not-a-Number DivideInfinityNaN.overflow: returns infinity of the correct sign.underFlow: returns de-normalized number.Conversion operationsFix: PROCEDURE [REAL] RETURNS [LONG INTEGER]; frG b qrqr `qr( ]nvw [v w Xr(qr"W;2qr!Uur'q TVeR9 Ou Lw Jf H6 FcJEQ BIx wMJ@ >qrqrq <\xw:r5xR3$qr'2pvr.0qr$qr/h,<#4*Cqr)4qr&,qZ$P#W br#qr* Cqr ZD /u)rCS=PK80C) u xw* y=]CMesa 6 Floating Point4FixI: PROCEDURE [REAL] RETURNS [INTEGER];FixC: PROCEDURE [REAL] RETURNS [CARDINAL];RoundLI: PROCEDURE [REAL] RETURNS [LONG INTEGER];RoundI: PROCEDURE [REAL] RETURNS [INTEGER];RoundC: PROCEDURE [REAL] RETURNS [CARDINAL];The Fix operations use rounding mode round-to-zero (truncation). The Round operationsuse mode round-to-nearest These operations can raise exceptions such as fixOverflow orinvalidOperation.Float: PROCEDURE [LONG INTEGER] RETURNS [REAL];Float is generated automatically by the compiler, but a client may wish to use it explicitly.Input and OutputReadReal: PROCEDURE [get: PROCEDURE RETURNS[CHARACTER],putback: PROCEDURE[CHARACTER] _ DefaultPutback] RETURNS [REAL];StringToReal: PROCEDURE [STRING] RETURNS [REAL];The procedures which convert to REAL may generate exceptions depending on the valuerepresented by the input. ReadReal must read past the end of the number input; it usesputback to return the last character read. DefaultPutback discards the character.MaxSinglePrecision: CARDINAL = 9;DefaultSinglePrecision: CARDINAL = 7;WriteReal: PROCEDURE [cp: PROCEDURE[CHARACTER], r: REAL,precision: CARDINAL _ DefaultSinglePrecision, forceE: BOOLEAN _ FALSE];AppendReal: PROCEDURE [s: STRING, r: REAL,precision: CARDINAL _ DefaultSinglePrecision, forceE: BOOLEAN _ FALSE];The procedures which convert from REAL will not generate exceptions. If forceE is TRUEor the value is not IN [0.000001..1000000) then the number will be printed in scientificnotation. The output value will have precision significant digits.in WFReal (exported by WFRealImpl)These procedures are intended for use as print procedures in the WriteFormatted package.See the WriteFormatted package documentation. WFReal and WFRealImpl are distributedwith the WriteFormatted package.InitWFReals: PROCEDURE;WFWriteReal: PROCEDURE [rp: UNSPECIFIED, f: STRING, p: PROCEDURE [CHARACTER]];WFWriteEReal: PROCEDURE [rp: UNSPECIFIED, f: STRING, p: PROCEDURE [CHARACTER]];in RealFns (exported by RealImpl)Exp: PROCEDURE [REAL] RETURNS [REAL];For an input argument n, returns en (e=2.718...). Computed by continued fractions. frG bxw% _xw& ]nxw* [xw% Xxw&VgrK TTS_ P4xw*Mr> Ju Gxw/JF$? Cx w$@rqr?A I=vrK :w! 9w% 6oxw/J5G 2x wJ0G.qr qr-q,rqr4 +iC (=t"%r<$a.&" x w x wC [x wC 0t! xw"r"0P K9XMesa 6 Floating Point5Log: PROCEDURE [base,arg: REAL] RETURNS [REAL];Computes logarithm to the base base of arg. Computed by Ln(arg)/Ln(base).Ln: PROCEDURE [REAL] RETURNS [REAL];Computes the natural logarithm (base e) of the input argument.SqRt: PROCEDURE [REAL] RETURNS [REAL];Calculates the square root of the input value by Newton's iteration.Root: PROCEDURE [index,arg: REAL] RETURNS [REAL];Calculates the index root of arg by e(Ln(arg)/index).Power: PROCEDURE [base,exponent: REAL] RETURNS [REAL];Calculates base to the exponent power by e(exponent*Ln(base)).Sin: PROCEDURE [radians: REAL] RETURNS [REAL];SinDeg: PROCEDURE [degrees: REAL] RETURNS [REAL];Cos: PROCEDURE [radians: REAL] RETURNS [REAL];CosDeg: PROCEDURE [degrees: REAL] RETURNS [REAL];Tan: PROCEDURE [radians: REAL] RETURNS [REAL];TanDeg: PROCEDURE [degrees: REAL] RETURNS [REAL];Computes the trigonometric function by polynomial; good to 7.33 decimal places.ArcTan: PROCEDURE [y, x: REAL] RETURNS [radians: REAL];ArcTanDeg: PROCEDURE [y, x: REAL] RETURNS [degrees: REAL];Good to 8.7 decimal places.AlmostZero: PROC [x: REAL, distance: [-126..127]] RETURNS [BOOLEAN];Returns TRUE if ABS[x]<2^distance.AlmostEqual: PROC [x, y: REAL, distance: [-126..127]] RETURNS [BOOLEAN];Returns TRUE if (ABS[x-y]/MAX[ABS[x],ABS[y]])<2^distance.in RealConvert (exported by RealConvertImpl)The module RealConvertImpl IMPORTS InlineDefs (inline procedures only).Mesa5ToIeee: PROC [LONG UNSPECIFIED] RETURNS [REAL];Converts a Mesa 5 REAL to an equivalent Mesa 6 REAL. frG bxw,^rvrvr [xw"X2r> Txw"QrD NFxw-JrvrvrKJ Gxw1DZr vrvr DDZ A xw+ >xw+ <xw+ 9xw+ 7xw+ 4xw+1UrO .xw1 +xw1(=r $x w:!r" Qx w=r9 t,rqr% 1x w)r4 6`XyMesa 6 Floating Point6BcplToIeee: PROC [LONG UNSPECIFIED] RETURNS [REAL];Converts a Bcpl REAL to an equivalent Mesa 6 REAL. Bcpl REALs occur in some Pressformat files.IeeeToBcpl: PROC [REAL] RETURNS [LONG UNSPECIFIED];Converts a Mesa 6 REAL to an equivalent Bcpl REAL. Bcpl REALs occur in some Pressformat files. This operation may raise the signal below on impossible conversions.CVError: ERROR;References[1] "An Implementation Guide to a Proposed Standard for Floating Point Arithmetic", Jerome T.Coonen, Computer Magazine, January, 1980.[2] Mesa 6.0 Compiler Update, Ed Satterthwaite, [Iris]Doc>Compiler60.memo, May 22,1980. frG bx w)_rC^B Zx w)XrCWS Sxwvw Pt Mrr>Kur H!8G?~ F=!c TIMESROMAN  TIMESROMAN TIMESROMAN LOGO TIMESROMAN  TIMESROMAN  HELVETICA  HELVETICA HELVETICA  ,"j/%#/B%mesafloat60.bravo Larry StewartNovember 4, 1980 2:58 PM