135 lines
11 KiB
HTML
135 lines
11 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 DECODE-FLOAT, SCALE-FLOAT...</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="v_most_p.htm">
|
|
<LINK REL=UP HREF="c_number.htm">
|
|
<LINK REL=NEXT HREF="f_float.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="v_most_p.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_float.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
|
|
|
|
<HR>
|
|
|
|
<A NAME="decode-float"><A NAME="scale-float"><A NAME="float-radix"><A NAME="float-sign"><A NAME="float-digits"><A NAME="float-precision"><A NAME="integer-decode-float"><I>Function</I> <B>DECODE-FLOAT, SCALE-FLOAT, FLOAT-RADIX, FLOAT-SIGN, FLOAT-DIGITS, FLOAT-PRECISION, INTEGER-DECODE-FLOAT</B></A></A></A></A></A></A></A> <P>
|
|
<P><B>Syntax:</B><P>
|
|
<P>
|
|
|
|
<B>decode-float</B> <I>float</I> => <I>significand, exponent, sign</I><P>
|
|
<P>
|
|
|
|
<B>scale-float</B> <I>float integer</I> => <I>scaled-float</I><P>
|
|
<P>
|
|
|
|
<B>float-radix</B> <I>float</I> => <I>float-radix</I><P>
|
|
<P>
|
|
|
|
<B>float-sign</B> <I>float-1 <TT>&optional</TT> float-2</I> => <I>signed-float</I><P>
|
|
<P>
|
|
|
|
<B>float-digits</B> <I>float</I> => <I>digits1</I><P>
|
|
<P>
|
|
|
|
<B>float-precision</B> <I>float</I> => <I>digits2</I><P>
|
|
<P>
|
|
|
|
<B>integer-decode-float</B> <I>float</I> => <I>significand, exponent, integer-sign</I><P>
|
|
<P>
|
|
<P><B>Arguments and Values:</B><P>
|
|
<P>
|
|
<I>digits1</I>---a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
|
<I>digits2</I>---a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
|
<I>exponent</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
|
<I>float</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
<I>float-1</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
<I>float-2</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
<I>float-radix</I>---an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
|
<I>integer</I>---a non-negative <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
|
<I>integer-sign</I>---the <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> <TT>-1</TT>, or the <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> <TT>1</TT>. <P>
|
|
<I>scaled-float</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
<I>sign</I>---A <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A> of the same <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> as <I>float</I> but numerically equal to <TT>1.0</TT> or <TT>-1.0</TT>. <P>
|
|
<I>signed-float</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
<I>significand</I>---a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
<P><B>Description:</B><P>
|
|
<P>
|
|
<A REL=DEFINITION HREF="#decode-float"><B>decode-float</B></A> computes three values that characterize <I>float</I>. The first value is of the same <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> as <I>float</I> and represents the significand. The second value represents the exponent to which the radix (notated in this description by <I>b</I>) must be raised to obtain the value that, when multiplied with the first result, produces the absolute value of <I>float</I>. If <I>float</I> is zero, any <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> value may be returned, provided that the identity shown for <A REL=DEFINITION HREF="#scale-float"><B>scale-float</B></A> holds. The third value is of the same <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> as <I>float</I> and is 1.0 if <I>float</I> is greater than or equal to zero or -1.0 otherwise. <P>
|
|
<A REL=DEFINITION HREF="#decode-float"><B>decode-float</B></A> divides <I>float</I> by an integral power of <I>b</I> so as to bring its value between 1/<I>b</I> (inclusive) and 1 (exclusive), and returns the quotient as the first value. If <I>float</I> is zero, however, the result equals the absolute value of <I>float</I> (that is, if there is a negative zero, its significand is considered to be a positive zero). <P>
|
|
<A REL=DEFINITION HREF="#scale-float"><B>scale-float</B></A> returns <TT>(* </TT><I>float</I><TT> (expt (float </TT><I>b</I><TT> </TT><I>float</I><TT>) </TT><I>integer</I><TT>))</TT>, where <I>b</I> is the radix of the floating-point representation. <I>float</I> is not necessarily between 1/<I>b</I> and 1. <P>
|
|
<A REL=DEFINITION HREF="#float-radix"><B>float-radix</B></A> returns the radix of <I>float</I>. <P>
|
|
<A REL=DEFINITION HREF="#float-sign"><B>float-sign</B></A> returns a number <TT>z</TT> such that <TT>z</TT> and <I>float-1</I> have the same sign and also such that <TT>z</TT> and <I>float-2</I> have the same absolute value. If <I>float-2</I> is not supplied, its value is <TT>(float 1 </TT><I>float-1</I><TT>)</TT>. If an implementation has distinct representations for negative zero and positive zero, then <TT>(float-sign -0.0)</TT> => <TT>-1.0</TT>. <P>
|
|
<A REL=DEFINITION HREF="#float-digits"><B>float-digits</B></A> returns the number of radix <I>b</I> digits used in the representation of <I>float</I> (including any implicit digits, such as a ``hidden bit''). <P>
|
|
<A REL=DEFINITION HREF="#float-precision"><B>float-precision</B></A> returns the number of significant radix <I>b</I> digits present in <I>float</I>; if <I>float</I> is a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A> zero, then the result is an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A> zero. <P>
|
|
For <A REL=DEFINITION HREF="26_glo_n.htm#normalized"><I>normalized</I></A> <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>floats</I></A>, the results of <A REL=DEFINITION HREF="#float-digits"><B>float-digits</B></A> and <A REL=DEFINITION HREF="#float-precision"><B>float-precision</B></A> are the same, but the precision is less than the number of representation digits for a <A REL=DEFINITION HREF="26_glo_d.htm#denormalized"><I>denormalized</I></A> or zero number. <P>
|
|
<A REL=DEFINITION HREF="#integer-decode-float"><B>integer-decode-float</B></A> computes three values that characterize <I>float</I> - the significand scaled so as to be an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>, and the same last two values that are returned by <A REL=DEFINITION HREF="#decode-float"><B>decode-float</B></A>. If <I>float</I> is zero, <A REL=DEFINITION HREF="#integer-decode-float"><B>integer-decode-float</B></A> returns zero as the first value. The second value bears the same relationship to the first value as for <A REL=DEFINITION HREF="#decode-float"><B>decode-float</B></A>: <P>
|
|
<PRE>
|
|
(multiple-value-bind (signif expon sign)
|
|
(integer-decode-float f)
|
|
(scale-float (float signif f) expon)) == (abs f)
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Examples:</B><P>
|
|
<P>
|
|
<PRE>
|
|
;; Note that since the purpose of this functionality is to expose
|
|
;; details of the implementation, all of these examples are necessarily
|
|
;; very implementation-dependent. Results may vary widely.
|
|
;; Values shown here are chosen consistently from one particular implementation.
|
|
(decode-float .5) => 0.5, 0, 1.0
|
|
(decode-float 1.0) => 0.5, 1, 1.0
|
|
(scale-float 1.0 1) => 2.0
|
|
(scale-float 10.01 -2) => 2.5025
|
|
(scale-float 23.0 0) => 23.0
|
|
(float-radix 1.0) => 2
|
|
(float-sign 5.0) => 1.0
|
|
(float-sign -5.0) => -1.0
|
|
(float-sign 0.0) => 1.0
|
|
(float-sign 1.0 0.0) => 0.0
|
|
(float-sign 1.0 -10.0) => 10.0
|
|
(float-sign -1.0 10.0) => -10.0
|
|
(float-digits 1.0) => 24
|
|
(float-precision 1.0) => 24
|
|
(float-precision least-positive-single-float) => 1
|
|
(integer-decode-float 1.0) => 8388608, -23, 1
|
|
</PRE>
|
|
</TT> <P>
|
|
<P><B>Side Effects:</B> None.
|
|
<P>
|
|
<P><B>Affected By:</B><P>
|
|
<P>
|
|
The implementation's representation for <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>floats</I></A>. <P>
|
|
<P><B>Exceptional Situations:</B><P>
|
|
<P>
|
|
The functions <A REL=DEFINITION HREF="#decode-float"><B>decode-float</B></A>, <A REL=DEFINITION HREF="#float-radix"><B>float-radix</B></A>, <A REL=DEFINITION HREF="#float-digits"><B>float-digits</B></A>, <A REL=DEFINITION HREF="#float-precision"><B>float-precision</B></A>, and <A REL=DEFINITION HREF="#integer-decode-float"><B>integer-decode-float</B></A> should signal an error if their only argument is not a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
The <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#scale-float"><B>scale-float</B></A> should signal an error if its first argument is not a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A> or if its second argument is not an <A REL=DEFINITION HREF="26_glo_i.htm#integer"><I>integer</I></A>. <P>
|
|
The <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#float-sign"><B>float-sign</B></A> should signal an error if its first argument is not a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A> or if its second argument is supplied but is not a <A REL=DEFINITION HREF="26_glo_f.htm#float"><I>float</I></A>. <P>
|
|
<P><B>See Also:</B> None.
|
|
<P>
|
|
<P><B>Notes:</B><P>
|
|
<P>
|
|
The product of the first result of <A REL=DEFINITION HREF="#decode-float"><B>decode-float</B></A> or <A REL=DEFINITION HREF="#integer-decode-float"><B>integer-decode-float</B></A>, of the radix raised to the power of the second result, and of the third result is exactly equal to the value of <I>float</I>. <P>
|
|
<PRE>
|
|
(multiple-value-bind (signif expon sign)
|
|
(decode-float f)
|
|
(scale-float signif expon))
|
|
== (abs f)
|
|
</PRE>
|
|
</TT> and <P>
|
|
<PRE>
|
|
(multiple-value-bind (signif expon sign)
|
|
(decode-float f)
|
|
(* (scale-float signif expon) sign))
|
|
== f
|
|
</PRE>
|
|
</TT> <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>
|