1 XEROX COMMON LISP DESIGN DOCUMENT CMLARITH2 1 CMLARITH2 6 Kelly Roach 26-MAR-86 Covering part of section 12.6. Mainly rounding fns. Remainder of section 12.6 is covered by CMLNUM. CMLARITH2 implements following fns: FLOOR TRUNCATE CEILING ROUND MOD REM FFLOOR FCEILING FTRUNCATE FROUND 2 Issues 1 (1) EXPORTS.ALL and every piece of the system that has ever been written uses CEIL, FLOOR, and MOD macros. MODARITH defines CEIL, FLOOR, FOLDHI,FOLDLO,MODUP,UNFOLD, and MOD macros. (2) ARITH.SLISP implements CIS. (3) Interlisp FIX and FIXR. FIX=TRUNCATE? FIXR=ROUND? Should FIX and FIXR continue to exist? 2 Decisions 1 (1) Just define CL:FLOOR, CL:MOD and friends to be in a different package, rather than hack EXPORTS.ALL. Systemtic replacement on all system source file is tricky, difficult. Why not use the package system instead? Because I think there will be a lot of confusion. This is not a case of IL:SIN vs CL:SIN, for example. In the IL:SIN vs CL:SIN fight, user of CL:SIN can just forget about using IL:SIN--forget that IL:SIN exists. In the case of CL:FLOOR and IL:FLOOR, system coders would routine have to be using both of CL:FLOOR and IL:FLOOR. I think we need to find a new name for EXPORTS.ALL macros FLOOR, MOD, and probably CEIL. I don't think even with the existence of a packages solution that we want the EXPORTS.ALL macros and the Common Lisp functions to have the same names. The EXPORTS.ALL macros will have to give way. All occurences of FLOOR, MOD, and CEIL in the system will have to be replaced by the new macro names. Do systematic replacement on every system source file. The definitions in MODARITH are admitedly hokey. It is possible that some day we might be able to use the "real" common Lisp definitions with suitable declarations and compiler work, but keeping them the same is a problem. (2) CIS is really a trig fn and is described in section 12.5. CMLIRRAT will implement CIS. (3) Probably not. But will do nothing about enabling them to no longer exist at this time. Not crucial to weed out use of old rounding fns in first release of Common Lisp. Minor pruning of the Interlisp bush has no effect. 2 Design overview 1 (1) Most of the code will be like FIX and FIXR. I see no serious problems other than that the code for FIXR is very hairy so that we may expect that the code for some of the fns in CMLARITH2 to be similarily hairy. (2) When LONG-FLOATs are implemented, will have to go back into CMLARITH2 code. LONG-FLOATs will not be implemented in first release of Common Lisp. 2 Algorithms and Data Structures 1 (1) Use LLFLOAT record declarations. (2) Use FIX and FIXR code to help in implementing TRUNCATE and ROUND. Must add DIVISOR arg. (3) Study FIXR code to help in implementing FLOOR and CEILING. Dependencies 1 (1) EXPORTS.ALL FLOOR, MOD, and CEIL macros have to be renamed. Uses of FLOOR, MOD, and CEIL have to be replaced by new names throughout system. Performance points 1 Compiler / evaluator: (FLOOR (\ X Y)) where X and Y are declared to be integers can be done with IQUOTIENT maybe, and we probably need to recognize the idioms in the compiler. Expect other (subtle) performance issues. Optimizer macros: CONSTANTEXPRESSIONP should know that all of the following fns are side effect free: FLOOR TRUNCATE CEILING ROUND MOD REM FFLOOR FCEILING FTRUNCATE FROUND. Microcode: It appears that (FIX N) is implemented by doing (IPLUS N 0) and that IPLUS2 opcode does FIXing: IVAR '0 IPLUS2 RETURN -X-. The Common Lisp equivalent of FIX is TRUNCATE which has slightly different arg list: (TRUNCATE NUMBER &OPTIONAL DIVISOR). I don't think new microcode support is needed here, but in implementing TRUNCATE we should use the same trick that FIX uses if DIVISOR=NIL, and otherwise handle TRUNCATE the hard way. Environment support 1 Environmental impact (tools needed, etc.): None Tasks 1 (1) Solicit new name from LISPCORE^ to replace MODARITH's MOD, FLOOR, and CEIL macros. Then do systemwide replace. (2) Implement p215 functions (FLOOR NUMBER &OPTIONAL DIVISOR) (CEILING NUMBER &OPTIONAL DIVISOR) (TRUNCATE NUMBER &OPTIONAL DIVISOR) (ROUND NUMBER &OPTIONAL DIVISOR) (3) Implement p217 functions (MOD NUMBER DIVISOR) (REM NUMBER DIVISOR) According to silver book, these seem to require that FLOOR and TRUNCATE are already implemented. (4) Implement p217 functions (FFLOOR NUMBER &OPTIONAL DIVISOR) (FCEILING NUMBER &OPTIONAL DIVISOR) (FTRUNCATE NUMBER &OPTIONAL DIVISOR) (FROUND NUMBER &OPTIONAL DIVISOR) Testing issues 1 (1) Page 215: (NUMERATOR (/ 8 -6)) => -4 (DENOMINATOR (/ 8 -6)) => 3 (2) Table on page 216. This table can also be used to test FFLOOR, FCEILING. FTRUNCATE, and FROUND. For these four functions, expect that FLOATPs will (can?) be returned. (3) Page 217: 12 MOD and REM cases to test. (4) Page 218: 2 FFLOOR cases to test. 2 Phasing and Timing 1 The implementation is phased: (1), (2), (3) as described in Tasks section. Time estimate: 10 days. 2 Appendix 1 (FLOOR NUMBER &OPTIONAL DIVISOR) (CEILING NUMBER &OPTIONAL DIVISOR) (TRUNCATE NUMBER &OPTIONAL DIVISOR) (ROUND NUMBER &OPTIONAL DIVISOR) (MOD NUMBER DIVISOR) (REM NUMBER DIVISOR) (FFLOOR NUMBER &OPTIONAL DIVISOR) (FCEILING NUMBER &OPTIONAL DIVISOR) (FTRUNCATE NUMBER &OPTIONAL DIVISOR) (FROUND NUMBER &OPTIONAL DIVISOR) (LIST ((PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC)) (0 0 612 792) ((HEADING NIL (HEADINGTYPE FOOTINGR) (72 27 540 36) NIL) (TEXT NIL NIL (72 72 504 648) NIL))) (PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC)) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD RIGHT) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC)) (288 12 288 36) NIL) (HEADING NIL (HEADINGTYPE FOOTINGR) (72 27 540 36) NIL) (HEADING NIL (HEADINGTYPE RECTOHEAD) (72 762 540 36) NIL) (TEXT NIL NIL (72 72 504 648) NIL))) (PAGE NIL (PAPERSIZE Letter FOLIOINFO (ARABIC)) (0 0 612 792) ((FOLIO NIL (PARALOOKS (QUAD RIGHT) CHARLOOKS (SUPERSCRIPT 0 INVISIBLE OFF SELECTPOINT OFF PROTECTED OFF SIZE 10 FAMILY MODERN OVERLINE OFF STRIKEOUT OFF UNDERLINE OFF EXPANSION REGULAR SLOPE REGULAR WEIGHT MEDIUM INVERTED OFF USERINFO NIL STYLE NIL) FORMATINFO (ARABIC)) (288 12 288 36) NIL) (HEADING NIL (HEADINGTYPE FOOTINGR) (72 27 540 36) NIL) (HEADING NIL (HEADINGTYPE RECTOHEAD) (72 762 540 36) NIL) (TEXT NIL NIL (72 72 504 648) NIL))))) /``øT/øT/ øT)T)2T(`` )``T)`` TBøø PAGEHEADING RECTOHEADAøø PAGEHEADINGFOOTINGR HELVETICAMODERN MODERNMODERNMODERN   HRULE.GETFNMODERN  "   HRULE.GETFNMODERN   HRULE.GETFNMODERN‹J HRULE.GETFNMODERN HRULE.GETFNMODERN¶ ` HRULE.GETFNMODERN  HRULE.GETFNMODERNÒ Þ\°1 HRULE.GETFNMODERN HRULE.GETFNMODERNØ– HRULE.GETFNMODERN HRULE.GETFNMODERN%]?  HRULE.GETFNMODERN ’ HRULE.GETFNMODERN  Œ º HRULE.GETFNMODERN 0 HRULE.GETFNMODERN t&()&a')*' HRULE.GETFNMODERN  !­,& HRULE.GETFNMODERN HRULE.GETFNMODERN2 HRULE.GETFNMODERN  HRULE.GETFNMODERN!#$!"$%"Þzº