85 lines
8.2 KiB
HTML
85 lines
8.2 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: Function EXP, EXPT</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="f_evenpc.htm">
|
|
<LINK REL=UP HREF="c_number.htm">
|
|
<LINK REL=NEXT HREF="f_gcd.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="f_evenpc.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_number.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_gcd.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="exp"><A NAME="expt"><I>Function</I> <B>EXP, EXPT</B></A></A> <P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>exp</B> <I>number</I> => <I>result</I><P>
|
|
|
|
<B>expt</B> <I>base-number power-number</I> => <I>result</I><P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>number</I>---a <A REL=DEFINITION HREF="26_glo_n.htm#number"><I>number</I></A>. <P>
|
|
<I>base-number</I>---a <A REL=DEFINITION HREF="26_glo_n.htm#number"><I>number</I></A>. <P>
|
|
<I>power-number</I>---a <A REL=DEFINITION HREF="26_glo_n.htm#number"><I>number</I></A>. <P>
|
|
<I>result</I>---a <A REL=DEFINITION HREF="26_glo_n.htm#number"><I>number</I></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="#exp"><B>exp</B></A> and <A REL=DEFINITION HREF="#expt"><B>expt</B></A> perform exponentiation. <P>
|
|
<A REL=DEFINITION HREF="#exp"><B>exp</B></A> returns <I>e</I> raised to the power <I>number</I>, where <I>e</I> is the base of the natural logarithms. <A REL=DEFINITION HREF="#exp"><B>exp</B></A> has no branch cut. <P>
|
|
<A REL=DEFINITION HREF="#expt"><B>expt</B></A> returns <I>base-number</I> raised to the power <I>power-number</I>. If the <I>base-number</I> is a <A REL=DEFINITION HREF="26_glo_r.htm#rational"><I>rational</I></A> and <I>power-number</I> is an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, the calculation is exact and the result will be of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="t_ration.htm#rational"><B>rational</B></A>; otherwise a floating-point approximation might result. For <A REL=DEFINITION HREF="#expt"><B>expt</B></A> of a <A REL=DEFINITION HREF="26_glo_c.htm#complex_rational"><I>complex rational</I></A> to an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> power, the calculation must be exact and the result is of type <TT>(or rational (complex rational))</TT>. <P>
|
|
The result of <A REL=DEFINITION HREF="#expt"><B>expt</B></A> can be a <A REL=DEFINITION HREF="26_glo_c.htm#complex"><I>complex</I></A>, even when neither argument is a <A REL=DEFINITION HREF="26_glo_c.htm#complex"><I>complex</I></A>, if <I>base-number</I> is negative and <I>power-number</I> is not an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. The result is always the <A REL=DEFINITION HREF="26_glo_p.htm#principal"><I>principal</I></A> <A REL=DEFINITION HREF="26_glo_c.htm#complex"><I>complex</I></A> <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A>. For example, <TT>(expt -8 1/3)</TT> is not permitted to return <TT>-2</TT>, even though <TT>-2</TT> is one of the cube roots of <TT>-8</TT>. The <A REL=DEFINITION HREF="26_glo_p.htm#principal"><I>principal</I></A> cube root is a <A REL=DEFINITION HREF="26_glo_c.htm#complex"><I>complex</I></A> approximately equal to <TT>#C(1.0 1.73205)</TT>, not <TT>-2</TT>. <P>
|
|
<A REL=DEFINITION HREF="#expt"><B>expt</B></A> is defined as <I>b^x = e^x log b</I>. This defines the <A REL=DEFINITION HREF="26_glo_p.htm#principal"><I>principal</I></A> <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>values</I></A> precisely. The range of <A REL=DEFINITION HREF="#expt"><B>expt</B></A> is the entire complex plane. Regarded as a function of <I>x</I>, with <I>b</I> fixed, there is no branch cut. Regarded as a function of <I>b</I>, with <I>x</I> fixed, there is in general a branch cut along the negative real axis, continuous with quadrant II. The domain excludes the origin. By definition, 0^0=1. If <I>b</I>=0 and the real part of <I>x</I> is strictly positive, then <I>b^x</I>=0. For all other values of <I>x</I>, 0^<I>x</I> is an error. <P>
|
|
When <I>power-number</I> is an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> <TT>0</TT>, then the result is always the value one in the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> of <I>base-number</I>, even if the <I>base-number</I> is zero (of any <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>). That is: <P>
|
|
<PRE>
|
|
(expt x 0) == (coerce 1 (type-of x))
|
|
</PRE>
|
|
</TT> If <I>power-number</I> is a zero of any other <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>, then the result is also the value one, in the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> of the arguments after the application of the contagion rules in <A REL=CHILD HREF="12_aab.htm">Section 12.1.1.2 (Contagion in Numeric Operations)</A>, with one exception: the consequences are undefined if <I>base-number</I> is zero when <I>power-number</I> is zero and not of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="t_intege.htm#integer"><B>integer</B></A>. <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
|
|
<PRE>
|
|
(exp 0) => 1.0
|
|
(exp 1) => 2.718282
|
|
(exp (log 5)) => 5.0
|
|
(expt 2 8) => 256
|
|
(expt 4 .5) => 2.0
|
|
(expt #c(0 1) 2) => -1
|
|
(expt #c(2 2) 3) => #C(-16 16)
|
|
(expt #c(2 2) 4) => -64
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Affected By:</B> None.
|
|
<P>
|
|
<P><B>Exceptional Situations:</B> None.
|
|
<P>
|
|
<P><B>See Also:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="f_log.htm#log"><B>log</B></A>, <A REL=CHILD HREF="12_acc.htm">Section 12.1.3.3 (Rule of Float Substitutability)</A> <P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
Implementations of <A REL=DEFINITION HREF="#expt"><B>expt</B></A> are permitted to use different algorithms for the cases of a <I>power-number</I> of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="t_ration.htm#rational"><B>rational</B></A> and a <I>power-number</I> of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="t_float.htm#float"><B>float</B></A>. <P>
|
|
<P>
|
|
Note that by the following logic, <TT>(sqrt (expt </TT><I>x</I><TT> 3))</TT> is not equivalent to <TT>(expt </TT><I>x</I><TT> 3/2)</TT>. <P>
|
|
<PRE>
|
|
(setq x (exp (/ (* 2 pi #c(0 1)) 3))) ;exp(2.pi.i/3)
|
|
(expt x 3) => 1 ;except for round-off error
|
|
(sqrt (expt x 3)) => 1 ;except for round-off error
|
|
(expt x 3/2) => -1 ;except for round-off error
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss153.htm">EXPT-RATIO:P.211</A><LI> <A REL=CHILD HREF="../Issues/iss071.htm">COMPLEX-RATIONAL-RESULT:EXTEND</A><P></UL><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>
|