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

158 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 IEEE-ATAN-BRANCH-CUT 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/iss191_w.htm">
<LINK REL=UP HREF="../Issues/iss192.htm">
<LINK REL=NEXT HREF="../Issues/iss193_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/iss191_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="../Issues/iss192.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="../Issues/iss193_w.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<H2>Issue IEEE-ATAN-BRANCH-CUT Writeup</H2>
<PRE><B>Status:</B> Passed, Jan 89 X3J13<P>
<B>Forum:</B> Cleanup<P>
<B>Issue:</B> <A HREF="iss192.htm">IEEE-ATAN-BRANCH-CUT</A><P>
<B>References:</B> CLtL p.203-214<P>
Related issues: <A HREF="iss069.htm">COMPLEX-ATAN-BRANCH-CUT</A><P>
<B>Category:</B> CHANGE<P>
<P>
<B>Edit history:</B> Version 1, 13-Dec-88, Steele<P>
Version 2, 11-Jan-89, Masinter <P>
<P>
<B>Problem description:<P>
</B><P>
If an implementation provides a floating-point minus zero as well as a<P>
floating-point plus zero, most notably as in IEEE 754 floating-point<P>
arithmetic, then slight adjustments in the branch cuts of transcendental<P>
functions are appropriate.<P>
<P>
If there is a minus zero and a plus zero, then *no* complex number<P>
is actually &quot;on the axis&quot; whether real or imaginary. Instead,<P>
numbers of the form x+0i and x-0i straddle the real axis, and those<P>
of the form 0+xi and -0+xi straddle the imginary axis. Branch cuts<P>
that lie on the axes therefore run between such numbers, and directions<P>
of continuity are not an issue.<P>
<P>
<B>Proposal (IEEE-ATAN-BRANCH-CUT:SPLIT):<P>
</B><P>
Redefine the branch cut for two-argument <A REL=DEFINITION HREF="../Body/f_asin_.htm#atan"><B>ATAN</B></A>, covering<P>
the cases where there is or is not a minus zero, and then redefine *all*<P>
other functions that have branch cuts in terms of two-argument <A REL=DEFINITION HREF="../Body/f_asin_.htm#atan"><B>ATAN</B></A>.<P>
Specifically, we first define <A REL=DEFINITION HREF="../Body/f_phase.htm#phase"><B>PHASE</B></A> in terms of two-argument <A REL=DEFINITION HREF="../Body/f_asin_.htm#atan"><B>ATAN</B></A>,<P>
and complex <A REL=DEFINITION HREF="../Body/f_abs.htm#abs"><B>ABS</B></A> in terms of real <A REL=DEFINITION HREF="../Body/f_sqrt_.htm#sqrt"><B>SQRT</B></A> (which has no branch cut problems);<P>
then define complex <A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> in terms of <A REL=DEFINITION HREF="../Body/f_phase.htm#phase"><B>PHASE</B></A>, <A REL=DEFINITION HREF="../Body/f_abs.htm#abs"><B>ABS</B></A>, and real LOG; then define<P>
complex <A REL=DEFINITION HREF="../Body/f_sqrt_.htm#sqrt"><B>SQRT</B></A> in terms of LOG; and then define all others in terms of these.<P>
<P>
In this propoal Lisp expressions should be taken as mathematical<P>
formulas that actually are implemented in other ways for improved accuracy.<P>
<P>
(1) If there is no minus zero, two-argument <A REL=DEFINITION HREF="../Body/f_asin_.htm#atan"><B>ATAN</B></A> behaves as in CLtL.<P>
If there is a minus zero, then some cases are modified:<P>
Condition result<P>
y=+0 x&gt;0 +0<P>
y=-0 x&gt;0 -0<P>
y=+0 x&lt;0 +pi<P>
y=-0 x&lt;0 -pi<P>
y=+0 x=+0 +0<P>
y=-0 x=+0 -0<P>
y=+0 x=-0 +pi<P>
y=-0 x=-0 -pi<P>
The range of two-argument <A REL=DEFINITION HREF="../Body/f_asin_.htm#atan"><B>atan</B></A> therefore includes -pi in this case.<P>
<P>
Note that the case y=0 x=0 is an error in the absence of minus zero,<P>
but is defined in the presence of minus zero.<P>
<P>
(2) (<A REL=DEFINITION HREF="../Body/f_phase.htm#phase"><B>PHASE</B></A> X) = (<A REL=DEFINITION HREF="../Body/f_asin_.htm#atan"><B>ATAN</B></A> (<A REL=DEFINITION HREF="../Body/f_realpa.htm#imagpart"><B>IMAGPART</B></A> X) (<A REL=DEFINITION HREF="../Body/f_realpa.htm#realpart"><B>REALPART</B></A> X)), as before, but now<P>
the range of <A REL=DEFINITION HREF="../Body/f_phase.htm#phase"><B>PHASE</B></A> may include -PI if there is a minus zero.<P>
<P>
(3) (<A REL=DEFINITION HREF="../Body/f_abs.htm#abs"><B>ABS</B></A> X) = (<A REL=DEFINITION HREF="../Body/f_sqrt_.htm#sqrt"><B>SQRT</B></A> (+ (* (<A REL=DEFINITION HREF="../Body/f_realpa.htm#realpart"><B>REALPART</B></A> X) (<A REL=DEFINITION HREF="../Body/f_realpa.htm#realpart"><B>REALPART</B></A> X))<P>
(* (<A REL=DEFINITION HREF="../Body/f_realpa.htm#imagpart"><B>IMAGPART</B></A> X) (<A REL=DEFINITION HREF="../Body/f_realpa.htm#imagpart"><B>IMAGPART</B></A> X)))), as before<P>
<P>
(4) (<A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> X) = (<A REL=DEFINITION HREF="../Body/a_comple.htm#complex"><B>COMPLEX</B></A> (<A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> (<A REL=DEFINITION HREF="../Body/f_abs.htm#abs"><B>ABS</B></A> X)) (<A REL=DEFINITION HREF="../Body/f_phase.htm#phase"><B>PHASE</B></A> X))<P>
<P>
(5) (<A REL=DEFINITION HREF="../Body/f_sqrt_.htm#sqrt"><B>SQRT</B></A> X) = (<A REL=DEFINITION HREF="../Body/f_exp_e.htm#exp"><B>EXP</B></A> (/ (<A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> X) 2))<P>
<P>
(6) For <A REL=DEFINITION HREF="../Body/f_exp_e.htm#expt"><B>EXPT</B></A>, <A REL=DEFINITION HREF="../Body/f_asin_.htm#asin"><B>ASIN</B></A>, <A REL=DEFINITION HREF="../Body/f_asin_.htm#acos"><B>ACOS</B></A>, <A REL=DEFINITION HREF="../Body/f_asin_.htm#atan"><B>ATAN</B></A>, <A REL=DEFINITION HREF="../Body/f_sinh_.htm#asinh"><B>ASINH</B></A>, <A REL=DEFINITION HREF="../Body/f_sinh_.htm#acosh"><B>ACOSH</B></A>, <A REL=DEFINITION HREF="../Body/f_sinh_.htm#atanh"><B>ATANH</B></A> use the formulas<P>
in CLtL pp. 211-213, but use the formulas (1-5) above as the<P>
definitions of <A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> and <A REL=DEFINITION HREF="../Body/f_sqrt_.htm#sqrt"><B>SQRT</B></A> in order to determine the branch cuts<P>
properly.<P>
<P>
<B>Examples:<P>
</B><P>
(<A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> #c(-1.0 +0.0)) =&gt; #c(0.0 3.14159...) ;Current<P>
(<A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> #c(-1.0 -0.0)) =&gt; #c(0.0 3.14159...) ;Current<P>
<P>
(<A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> #c(-1.0 +0.0)) =&gt; #c(0.0 3.14159...) ;Proposed (= current)<P>
(<A REL=DEFINITION HREF="../Body/f_log.htm#log"><B>LOG</B></A> #c(-1.0 -0.0)) =&gt; #c(0.0 -3.14159...) ;Proposed (conjugate)<P>
<P>
<B>Rationale:<P>
</B><P>
The current specification ignores some natural consequences of IEEE<P>
floating-point arithmetic. The proposed specification produces results<P>
more natural to that arithmetic.<P>
<P>
<P>
<B>Current practice:<P>
</B><P>
Of implementations that support a minus zero that I have checked,<P>
such as Sun-4 CL 2.1.3 of 10-Nov-88 and Symbolics CL, all follow<P>
the current CLtL specification.<P>
<P>
The IEEE trig library atan2 routine written by K.C. Ng (with the advice<P>
or supervision of W. Kahan, I believe), and distributed with BSD UNIX<P>
(it is file /usr/src/usr.lib/libm/IEEE/atan2.c on my machine) follows<P>
this proposal for treatment of minus zero.<P>
<P>
<P>
<B>Cost to Implementors:<P>
</B><P>
Some of the trig routines will <A REL=DEFINITION HREF="../Body/f_provid.htm#require"><B>require</B></A> some rewriting. Probably certain<P>
tests that are now written using <A REL=DEFINITION HREF="../Body/f_zerop.htm#zerop"><B>ZEROP</B></A> need to be rewritten to use<P>
<A REL=DEFINITION HREF="../Body/f_dec_fl.htm#float-sign"><B>FLOAT-SIGN</B></A> instead.<P>
<P>
<P>
<B>Cost to Users:<P>
</B><P>
It is barely conceivable that some user code could depend on this.<P>
Probably there is no cost.<P>
<P>
The compatibility note on p. 210 of CLtL gave users fair warning that<P>
a change of this kind might be adopted.<P>
<P>
<B>Cost of non-adoption:<P>
</B><P>
Unnatural treatment of some functions on machines supporting IEEE<P>
floating-point arithmetic.<P>
<P>
<B>Benefits:<P>
</B><P>
Natural treatment, etc.<P>
<P>
<B>Esthetics:<P>
</B><P>
A toss-up, except to those who care.<P>
<P>
<B>Discussion:<P>
</B><P>
Steele has sent a letter to W. Kahan at Berkeley to get any last<P>
comments he may have on the matter.<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>