1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Issues/iss071_w.htm
2024-04-01 10:24:07 +02:00

125 lines
7.9 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 COMPLEX-RATIONAL-RESULT 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/iss070_w.htm">
<LINK REL=UP HREF="../Issues/iss071.htm">
<LINK REL=NEXT HREF="../Issues/iss072_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/iss070_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss071.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss072_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue COMPLEX-RATIONAL-RESULT Writeup</H2>
<PRE><B>Issue:</B> <A HREF="iss071.htm">COMPLEX-RATIONAL-RESULT</A><P>
<P>
<B>References:</B> CLtL p.203<P>
<P>
<B>Category:</B> CLARIFICATION<P>
<P>
<B>Edit history:</B> Version 1, 20-Mar-89, by Moon<P>
Version 2, 08-Apr-89, by Steele<P>
Version 3, 28-Apr-89, by Steele<P>
<P>
<B>Problem description:<P>
</B> <P>
Referring to irrational and transcendental functions, CLtL says:<P>
<P>
When the arguments to a function in this section are all rational and<P>
the true mathematical result is also (mathematically) rational, then<P>
unless otherwise noted an implementation is free to return either an<P>
accurate result of type rational or a single-precision floating-point<P>
approximation. If the arguments are all rational but the result cannot<P>
be expressed as a rational number, then a single-precision<P>
floating-point approximation is always returned.<P>
<P>
Referring to <A REL=DEFINITION HREF="../Body/f_exp_e.htm#expt"><B>EXPT</B></A>, CLtL says:<P>
<P>
If the base-number is of type <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A> and the power-number is an<P>
<A REL=DEFINITION HREF="../Body/t_intege.htm#integer"><B>INTEGER</B></A>, the calculation will be exact and the result will be of<P>
type RATIONAL; otherwise a floating-point approximation may result.<P>
<P>
What about arguments of type (complex rational)?<P>
<P>
<B>Proposal (COMPLEX-RATIONAL-RESULT:EXTEND):<P>
</B><P>
Extend the paragraph quoted above as follows to cover the components<P>
of complex numbers. If the arguments to a function are all of type<P>
(<A REL=DEFINITION HREF="../Body/a_or.htm#or"><B>OR</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A> (<A REL=DEFINITION HREF="../Body/a_comple.htm#complex"><B>COMPLEX</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A>)) and the true mathematical result is<P>
(mathematically) a complex number with rational real and imaginary<P>
parts, then unless otherwise noted an implementation is free to return<P>
either an accurate result of type (<A REL=DEFINITION HREF="../Body/a_or.htm#or"><B>OR</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A> (<A REL=DEFINITION HREF="../Body/a_comple.htm#complex"><B>COMPLEX</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A>)) or<P>
a single-precision floating-point approximation of type <A REL=DEFINITION HREF="../Body/t_short_.htm#single-float"><B>SINGLE-FLOAT</B></A><P>
(permissible only <A REL=DEFINITION HREF="../Body/s_if.htm#if"><B>if</B></A> <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>the</B></A> imaginary part of <A REL=DEFINITION HREF="../Body/s_the.htm#the"><B>the</B></A> true mathematical<P>
result is zero) or (<A REL=DEFINITION HREF="../Body/a_comple.htm#complex"><B>COMPLEX</B></A> <A REL=DEFINITION HREF="../Body/t_short_.htm#single-float"><B>SINGLE-FLOAT</B></A>). If the arguments are<P>
all of type (<A REL=DEFINITION HREF="../Body/a_or.htm#or"><B>OR</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A> (<A REL=DEFINITION HREF="../Body/a_comple.htm#complex"><B>COMPLEX</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A>)) but the result cannot be<P>
expressed as a rational or complex rational number, then the returned<P>
value will be of type <A REL=DEFINITION HREF="../Body/t_short_.htm#single-float"><B>SINGLE-FLOAT</B></A> (permissible only if the imaginary<P>
part of the true mathematical result is zero) or (<A REL=DEFINITION HREF="../Body/a_comple.htm#complex"><B>COMPLEX</B></A> <A REL=DEFINITION HREF="../Body/t_short_.htm#single-float"><B>SINGLE-FLOAT</B></A>).<P>
<P>
For <A REL=DEFINITION HREF="../Body/f_exp_e.htm#expt"><B>EXPT</B></A> of a (<A REL=DEFINITION HREF="../Body/a_comple.htm#complex"><B>COMPLEX</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A>) to an integer power, the<P>
calculation must be exact and the result will be of type<P>
(<A REL=DEFINITION HREF="../Body/a_or.htm#or"><B>OR</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A> (<A REL=DEFINITION HREF="../Body/a_comple.htm#complex"><B>COMPLEX</B></A> <A REL=DEFINITION HREF="../Body/a_ration.htm#rational"><B>RATIONAL</B></A>)).<P>
<P>
<B>Examples:<P>
</B><P>
[a] (log #c(-16 16) #c(2 2)) =&gt; 3 or approximately #c(3.0 0.0)<P>
or approximately 3.0 (unlikely)<P>
[b] (abs #c(3/5 4/5)) =&gt; 1 or approximately 1.0<P>
[c] (<A REL=DEFINITION HREF="../Body/f_exp_e.htm#expt"><B>expt</B></A> #c(2 2) 3) =&gt; #c(-16 16)<P>
[d] (<A REL=DEFINITION HREF="../Body/f_exp_e.htm#expt"><B>expt</B></A> #c(2 2) 4) =&gt; -64 <P>
<P>
<B>Rationale:<P>
</B> <P>
This seems most consistent with the treatment of real numbers.<P>
<P>
<B>Current practice:<P>
</B> <P>
[a] [b] [c] [d]<P>
Symbolics Genera 7.4 #c(3.00... 1.40...e-7) 1 #c(-16 16) -64<P>
Sun Common Lisp 3.0.1 #c(3.0 2.61...e-16) 1.0 #c(-16 16) -64<P>
KCL of 9/16/86 on VAX #c(3.0s0 -1.40...s-7) 1.0s0 #c(-16 16) -64<P>
Allegro CL (Mac II) #c(3.0 2.05...e-16) 1.0 #c(-16 16) -64<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Only <A REL=DEFINITION HREF="../Body/f_exp_e.htm#expt"><B>EXPT</B></A> would have to change, since the type of the other results<P>
is at the discretion of the implementation.<P>
<P>
<B>Cost to Users:<P>
</B><P>
Probably none, but it is hard to predict.<P>
<P>
<B>Cost of non-adoption:<P>
</B> <P>
Slightly less self-consistent language.<P>
<P>
<B>Performance impact:<P>
</B><P>
None of any significance.<P>
<P>
<B>Benefits/Esthetics:<P>
</B><P>
More self-consistent language.<P>
<P>
<B>Discussion:<P>
</B><P>
None.<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>