159 lines
9.8 KiB
HTML
159 lines
9.8 KiB
HTML
|
<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
|
||
|
<HTML>
|
||
|
<HEAD>
|
||
|
<TITLE>CLHS: Issue FIXNUM-NON-PORTABLE Writeup</TITLE>
|
||
|
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
|
||
|
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
|
||
|
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
|
||
|
<LINK REL=TOP HREF="../Front/index.htm">
|
||
|
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
|
||
|
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
|
||
|
<LINK REL=PREV HREF="../Issues/iss157_w.htm">
|
||
|
<LINK REL=UP HREF="../Issues/iss158.htm">
|
||
|
<LINK REL=NEXT HREF="../Issues/iss159_w.htm">
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="../Issues/iss157_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss158.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss159_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
||
|
|
||
|
<HR>
|
||
|
|
||
|
|
||
|
|
||
|
<H2>Issue FIXNUM-NON-PORTABLE Writeup</H2>
|
||
|
|
||
|
<PRE><B>Status:</B> Passed Jan 89 X3J13, as amended<P>
|
||
|
<B>Issue:</B> <A HREF="iss158.htm">FIXNUM-NON-PORTABLE</A><P>
|
||
|
<B>References:</B> CLtL p. 14, 34, 43, 231<P>
|
||
|
<B>Category:</B> CHANGE, CLARIFICATION<P>
|
||
|
<P>
|
||
|
<B>Edit History:</B> Version 1, 11-Jul-88, Sandra Loosemore<P>
|
||
|
Version 2, 15-Sep-88, Masinter<P>
|
||
|
Version 3, 23-Sep-88, Masinter<P>
|
||
|
Version 4, 7-Dec-88, Masinter (two proposals)<P>
|
||
|
Version 5, 16-Mar-89, Masinter (incorporate amendments)<P>
|
||
|
Version 6, 17-Mar-89, Masinter (incorporate amendments correctly)<P>
|
||
|
<P>
|
||
|
<B>Problem Description: <P>
|
||
|
</B><P>
|
||
|
Implementations of Common Lisp are required to support two disjoint<P>
|
||
|
subsets of integers, fixnums and bignums, with the promise that<P>
|
||
|
fixnums have a more efficient representation. However, nothing is<P>
|
||
|
guaranteed about the range of integers which are fixnums: "Exactly<P>
|
||
|
which integers are fixnums is implementation-dependent; typically they<P>
|
||
|
will be those integers in the range -2**n to 2**n - 1, inclusive, for<P>
|
||
|
some n not less than 15."<P>
|
||
|
<P>
|
||
|
There are few uses of the <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>fixnum</B></A> type that are portable, given the<P>
|
||
|
current definition. In particular, many programmers use <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> type<P>
|
||
|
declarations where they really mean "small integer".<P>
|
||
|
<P>
|
||
|
While most Common Lisp implementations have a <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> range<P>
|
||
|
which is a subset of integers represeted and operated on most<P>
|
||
|
efficiently, many also have several other subranges. The<P>
|
||
|
partitioning of <A REL=DEFINITION HREF="../Body/t_intege.htm#integer"><B>INTEGER</B></A> into <A REL=DEFINITION HREF="../Body/t_bignum.htm#bignum"><B>BIGNUM</B></A> and <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> is merely<P>
|
||
|
confusing in these implementations, and not useful.<P>
|
||
|
<P>
|
||
|
CLtL p14 and p34 disagree about <A REL=DEFINITION HREF="../Body/t_bignum.htm#bignum"><B>BIGNUM</B></A>. One says that<P>
|
||
|
<A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> and <A REL=DEFINITION HREF="../Body/t_bignum.htm#bignum"><B>BIGNUM</B></A> are an exhaustive partition of the<P>
|
||
|
integer space, the other says they might not be!<P>
|
||
|
<P>
|
||
|
Proposal: FIXNUM-NONPORTABLE:TIGHTEN-DEFINITION<P>
|
||
|
<P>
|
||
|
(1) Change the description of the type <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> to reflect that it is<P>
|
||
|
required to be a supertype of (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 16).<P>
|
||
|
<P>
|
||
|
(2) Define <A REL=DEFINITION HREF="../Body/t_bignum.htm#bignum"><B>BIGNUM</B></A> to be exactly (<A REL=DEFINITION HREF="../Body/a_and.htm#and"><B>AND</B></A> <A REL=DEFINITION HREF="../Body/t_intege.htm#integer"><B>INTEGER</B></A> (<A REL=DEFINITION HREF="../Body/a_not.htm#not"><B>NOT</B></A> <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A>))<P>
|
||
|
<P>
|
||
|
(3) <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> that (<A REL=DEFINITION HREF="../Body/f_eq_sle.htm#LTEQ"><B><=</B></A> <A REL=DEFINITION HREF="../Body/v_ar_dim.htm#array-dimension-limit"><B>ARRAY-DIMENSION-LIMIT</B></A> <A REL=DEFINITION HREF="../Body/v_most_p.htm#most-positive-fixnum"><B>MOST-POSITIVE-FIXNUM</B></A>)<P>
|
||
|
<P>
|
||
|
<B>Example:<P>
|
||
|
</B><P>
|
||
|
Consider an implementation with three numeric representations:<P>
|
||
|
<P>
|
||
|
Fast (<A REL=DEFINITION HREF="../Body/t_intege.htm#integer"><B>INTEGER</B></A> -1024 1023)<P>
|
||
|
Immediate 29 bits<P>
|
||
|
Extended Multi-precision<P>
|
||
|
<P>
|
||
|
Such an implementation would have to define<P>
|
||
|
<A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> to be (<A REL=DEFINITION HREF="../Body/a_or.htm#or"><B>OR</B></A> Fast Immediate). <A REL=DEFINITION HREF="../Body/t_bignum.htm#bignum"><B>BIGNUM</B></A><P>
|
||
|
would then refer to multi-precision integers. <P>
|
||
|
<P>
|
||
|
<B>Rationale:<P>
|
||
|
</B><P>
|
||
|
Many programmers already use <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> to mean "small integer"; this<P>
|
||
|
proposal makes this usage portable. <P>
|
||
|
<P>
|
||
|
However, there is little portable use for the type <A REL=DEFINITION HREF="../Body/t_bignum.htm#bignum"><B>BIGNUM</B></A>, and it<P>
|
||
|
is inconsistent with many current implementation techniques.<P>
|
||
|
Removing it is an incompatible change for a weak reason.<P>
|
||
|
<P>
|
||
|
<B>Current Practice:<P>
|
||
|
</B><P>
|
||
|
Xerox Common Lisp has 17-bit fixnums. Most other Common Lisp<P>
|
||
|
implementations have <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>fixnum</B></A> ranges of 24 bits or larger. We know<P>
|
||
|
of no implementation that currently violates the proposed minimum <P>
|
||
|
size.<P>
|
||
|
<P>
|
||
|
Several existing Common Lisp implementations have more than two <P>
|
||
|
representations for integers, such that the FIXNUM/BIGNUM distinction<P>
|
||
|
is confusing; they define <A REL=DEFINITION HREF="../Body/t_bignum.htm#bignum"><B>BIGNUM</B></A> to cover all of the larger number<P>
|
||
|
types.<P>
|
||
|
<P>
|
||
|
<B>Cost to implementors:<P>
|
||
|
</B><P>
|
||
|
Slight. All implementations we know of already define FIXNUMs to be at<P>
|
||
|
least 16 bits.<P>
|
||
|
<P>
|
||
|
<B>Cost to users:<P>
|
||
|
</B><P>
|
||
|
Slight. <P>
|
||
|
<P>
|
||
|
<B>Benefits:<P>
|
||
|
</B><P>
|
||
|
The <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> type specifier would have a portable interpretation.<P>
|
||
|
<P>
|
||
|
The language would be less confusing.<P>
|
||
|
<P>
|
||
|
<B>Discussion:<P>
|
||
|
</B><P>
|
||
|
There was little consensus on whether to leave <A REL=DEFINITION HREF="../Body/t_bignum.htm#bignum"><B>BIGNUM</B></A> in the language.<P>
|
||
|
<P>
|
||
|
Earlier discussion of a related proposal contained several other more<P>
|
||
|
controversial components (adding a constant MAX-INTEGER-LENGTH, allowing <P>
|
||
|
<A REL=DEFINITION HREF="../Body/v_most_p.htm#most-positive-fixnum"><B>MOST-POSITIVE-FIXNUM</B></A> to be <A REL=DEFINITION HREF="../Body/a_nil.htm#nil"><B>NIL</B></A> as well as an integer.) This proposal<P>
|
||
|
is an attempt to address the part that cleanup committee seemed to agree<P>
|
||
|
on.<P>
|
||
|
<P>
|
||
|
It is possible that an implementation have a single representation for all<P>
|
||
|
integers, and no way to identify any efficient range of integers. Those<P>
|
||
|
implementations might need to set <A REL=DEFINITION HREF="../Body/v_most_p.htm#most-positive-fixnum"><B>MOST-POSITIVE-FIXNUM</B></A><P>
|
||
|
and <A REL=DEFINITION HREF="../Body/v_most_p.htm#most-negative-fixnum"><B>MOST-NEGATIVE-FIXNUM</B></A> to arbitrary values, consistent with <P>
|
||
|
the requirement that (<A REL=DEFINITION HREF="../Body/t_sgn_by.htm#signed-byte"><B>SIGNED-BYTE</B></A> 16) is a subtype of <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A>.<P>
|
||
|
<P>
|
||
|
Other alternatives considered (and not necessarily mutually exclusive<P>
|
||
|
with this proposal):<P>
|
||
|
<P>
|
||
|
remove the <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> type specifier entirely, while leaving a way<P>
|
||
|
to query what is the most efficient range of integers<P>
|
||
|
<P>
|
||
|
leave the range of FIXNUMs unconstrained and introduce a <P>
|
||
|
SMALL-INTEGER type with a fixed range (but no promises about<P>
|
||
|
efficiency) . <P>
|
||
|
<P>
|
||
|
It might be possible to specify the required performance behavior<P>
|
||
|
of FIXNUMs more concretely, e.g., specify that the basic integer operations<P>
|
||
|
use algorithms that are not proportional to the size of the data; it <P>
|
||
|
should be just about as fast to add numbers in the middle of the <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>fixnum</B></A> <P>
|
||
|
range as it is to add, say, 10 and 11. This might be a useful way to<P>
|
||
|
describe<P>
|
||
|
the intent of the <A REL=DEFINITION HREF="../Body/t_fixnum.htm#fixnum"><B>FIXNUM</B></A> range, if not its specification.<P>
|
||
|
<P>
|
||
|
</PRE>
|
||
|
<HR>
|
||
|
|
||
|
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
|
||
|
|
||
|
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
|
||
|
</BODY>
|
||
|
</HTML>
|