⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r5rs-z-h-9.html

📁 scheme 标准(r5rs)。Scheme是MIT发布的基于Lambda运算的语言
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_306"></a>truncate<i> x</i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_308"></a>round<i> x</i>)</tt>&nbsp;</div><p>These procedures return integers.<tt>Floor</tt> returns the largest integer not larger than <em>x</em>.<tt>Ceiling</tt> returns the smallest integer not smaller than&nbsp;<em>x</em>.<tt>Truncate</tt> returns the integer closest to <em>x</em> whose absolutevalue is not larger than the absolute value of <em>x</em>.  <tt>Round</tt> returns theclosest integer to <em>x</em>, rounding to even when <em>x</em> is halfway between twointegers.<p><blockquote><em>Rationale:&nbsp;&nbsp;</em><tt>Round</tt> rounds to even for consistency with the default roundingmode specified by the IEEE floating point standard.</blockquote><p><blockquote><em>Note:&nbsp;&nbsp;</em>If the argument to one of these procedures is inexact, then the resultwill also be inexact.  If an exact value is needed, theresult should be passed to the <tt>inexact-&gt;exact</tt> procedure.</blockquote><p><tt><p>(floor&nbsp;-4.3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;&nbsp;-5.0<br>(ceiling&nbsp;-4.3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;&nbsp;-4.0<br>(truncate&nbsp;-4.3)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n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sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;&nbsp;7<p></tt><p><p><p><p><div align=left><u>library procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_310"></a>rationalize<i> x y</i>)</tt>&nbsp;</div><p><tt>Rationalize</tt> returns the <em>simplest</em> rational numberdiffering from <em>x</em> by no more than <em>y</em>.  A rational number <em>r</em><sub>1</sub> is<em>simpler</em> <a name="%_idx_312"></a> than another rational number<em>r</em><sub>2</sub> if <em>r</em><sub>1</sub>  =  <em>p</em><sub>1</sub>/<em>q</em><sub>1</sub> and <em>r</em><sub>2</sub>  =  <em>p</em><sub>2</sub>/<em>q</em><sub>2</sub> (in lowest terms) and |<em>p</em><sub>1</sub>|<u>&lt;</u> |<em>p</em><sub>2</sub>| and |<em>q</em><sub>1</sub>| <u>&lt;</u> |<em>q</em><sub>2</sub>|.  Thus 3/5 is simpler than 4/7.Although not all rationals are comparable in this ordering (consider 2/7and 3/5) any interval contains a rational number that is simpler thanevery other rational number in that interval (the simpler 2/5 liesbetween 2/7 and 3/5).  Note that 0  =  0/1 is the simplest rational ofall.<p><tt><p>(rationalize<br>&nbsp;&nbsp;(inexact-&gt;exact&nbsp;.3)&nbsp;1/10)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;1/3&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;exact<br>(rationalize&nbsp;.3&nbsp;1/10)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;#i1/3&nbsp;&nbsp;;&nbsp;inexact<p></tt><p><p><p><p><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_314"></a>exp<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_316"></a>log<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_318"></a>sin<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_320"></a>cos<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_322"></a>tan<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_324"></a>asin<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_326"></a>acos<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_328"></a>atan<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(atan<i> <em>y</em> <em>x</em></i>)</tt>&nbsp;</div><p>These procedures are part of every implementation that supportsgeneralreal numbers; they compute the usual transcendental functions.  <tt>Log</tt>computes the natural logarithm of <em>z</em> (not the base ten logarithm).<tt>Asin</tt>, <tt>acos</tt>, and <tt>atan</tt> compute arcsine (<tt>sin</tt><sup>-1</sup>),arccosine (<tt>cos</tt><sup>-1</sup>), and arctangent (<tt>tan</tt><sup>-1</sup>), respectively.The two-argument variant of <tt>atan</tt> computes <tt>(angle(make-rectangular <em>x</em> <em>y</em>))</tt> (see below), even in implementationsthat don't support general complex numbers.<p>In general, the mathematical functions log, arcsine, arccosine, andarctangent are multiply defined.The value of <tt>log</tt> <em>z</em> is defined to be the one whose imaginarypart lies in the range from  - <img src="r5rs-Z-G-D-3.gif" border="0"> (exclusive) to <img src="r5rs-Z-G-D-3.gif" border="0"> (inclusive).<tt>log</tt> 0 is undefined.With <tt>log</tt> defined this way, the values of <tt>sin</tt><sup>-1</sup> <em>z</em>, <tt>cos</tt><sup>-1</sup> <em>z</em>,and <tt>tan</tt><sup>-1</sup> <em>z</em> are according to the following formul&aelig;:<p><div align=left><table><tr><td><tt>sin</tt><sup>-1</sup> <em>z</em>  =   - <em>i</em> <tt>log</tt> (<em>i</em> <em>z</em>  +  (1  -  <em>z</em><sup>2</sup>)<sup>1/2</sup>)</td></tr></table></div><p><p><div align=left><table><tr><td><tt>cos</tt><sup>-1</sup> <em>z</em>  =  <img src="r5rs-Z-G-D-3.gif" border="0"> / 2  -  <tt>sin</tt><sup>-1</sup> <em>z</em></td></tr></table></div><p><p><div align=left><table><tr><td><tt>tan</tt><sup>-1</sup> <em>z</em>  =  (<tt>log</tt> (1  +  <em>i</em> <em>z</em>)  -  <tt>log</tt> (1  -  <em>i</em> <em>z</em>)) / (2 <em>i</em>)</td></tr></table></div><p><p>The above specification follows&nbsp;[<a href="r5rs-Z-H-14.html#%_sec_7.3">27</a>], which in turncites&nbsp;[<a href="r5rs-Z-H-14.html#%_sec_7.3">19</a>]; refer to these sources for more detaileddiscussion of branch cuts, boundary conditions, and implementation ofthese functions.  When it is possible these procedures produce a realresult from a real argument.<p><p><p><p><p><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_330"></a>sqrt<i> <em>z</em></i>)</tt>&nbsp;</div><p>Returns the principal square root of <em>z</em>.  The result will haveeither positive real part, or zero real part and non-negative imaginarypart.<p><p><p><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_332"></a>expt<i> <em>z</em><sub>1</sub> <em>z</em><sub>2</sub></i>)</tt>&nbsp;</div><p>Returns <em>z</em><sub>1</sub> raised to the power <em>z</em><sub>2</sub>.  For <em>z</em><sub>1</sub> <img src="r5rs-Z-G-D-8.gif" border="0"> 0<p><div align=left><table><tr><td><em>z</em><sub>1</sub><sup><em>z</em><sub>2</sub></sup>  =  <em>e</em><sup><em>z</em><sub>2</sub> <tt>log</tt> <em>z</em><sub>1</sub></sup></td></tr></table></div><p>0<sup><em>z</em></sup> is 1 if <em>z</em>  =  0 and 0 otherwise.<p><p><p><p><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_334"></a>make-rectangular<i> <em>x</em><sub>1</sub> <em>x</em><sub>2</sub></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_336"></a>make-polar<i> <em>x</em><sub>3</sub> <em>x</em><sub>4</sub></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_338"></a>real-part<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_340"></a>imag-part<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_342"></a>magnitude<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_344"></a>angle<i> <em>z</em></i>)</tt>&nbsp;</div><p>These procedures are part of every implementation that supportsgeneralcomplex numbers.  Suppose <em>x</em><sub>1</sub>, <em>x</em><sub>2</sub>, <em>x</em><sub>3</sub>, and <em>x</em><sub>4</sub> arereal numbers and <em>z</em> is a complex number such that<p><div align=left><table><tr><td> <em>z</em>  =  <em>x</em><sub>1</sub>  +  <em>x</em><sub>2</sub><em>i</em> =  <em>x</em><sub>3</sub>  &middot;  <em>e</em><sup><em>i</em> <em>x</em><sub>4</sub></sup></td></tr></table></div><p>Then<tt><p>(make-rectangular&nbsp;<em>x</em><sub>1</sub>&nbsp;<em>x</em><sub>2</sub>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;<em>z</em><br>(make-polar&nbsp;<em>x</em><sub>3</sub>&nbsp;<em>x</em><sub>4</sub>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;<em>z</em><br>(real-part&nbsp;<em>z</em>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;<em>x</em><sub>1</sub><br>(imag-part&nbsp;<em>z</em>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;<em>x</em><sub>2</sub><br>(magnitude&nbsp;<em>z</em>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;|<em>x</em><sub>3</sub>|<br>(angle&nbsp;<em>z</em>)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;===&gt;&nbsp;<em>x</em><sub><em>a</em><em>n</em><em>g</em><em>l</em><em>e</em></sub><br><p></tt>where  - <img src="r5rs-Z-G-D-3.gif" border="0"> &lt; <em>x</em><sub><em>a</em><em>n</em><em>g</em><em>l</em><em>e</em></sub> <u>&lt;</u> <img src="r5rs-Z-G-D-3.gif" border="0"> with <em>x</em><sub><em>a</em><em>n</em><em>g</em><em>l</em><em>e</em></sub>  =  <em>x</em><sub>4</sub>  +  2<img src="r5rs-Z-G-D-3.gif" border="0"> <em>n</em>for some integer <em>n</em>.<p><blockquote><em>Rationale:&nbsp;&nbsp;</em><tt>Magnitude</tt> is the same as <tt>abs</tt> for a real argument,but <tt>abs</tt> must be present in all implementations, whereas<tt>magnitude</tt> need only be present in implementations that supportgeneral complex numbers.</blockquote><p><p><p><p><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_346"></a>exact-&gt;inexact<i> <em>z</em></i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_348"></a>inexact-&gt;exact<i> <em>z</em></i>)</tt>&nbsp;</div><p><tt>Exact-&gt;inexact</tt> returns an inexact representation of <em>z</em>.The value returned is theinexact number that is numerically closest to the argument.  If an exact argument has no reasonably close inexact equivalent,then a violation of an implementation restriction may be reported.<p><tt>Inexact-&gt;exact</tt> returns an exact representation of<em>z</em>.  The value returned is the exact number that is numericallyclosest to the argument.If an inexact argument has no reasonably close exact equivalent,then a violation of an implementation restriction may be reported.<p>These procedures implement the natural one-to-one correspondence betweenexact and inexact integers throughout animplementation-dependent range.  See section&nbsp;<a href="#%_sec_6.2.3">6.2.3</a>.<p><p><p><p><p><p><a name="%_sec_6.2.6"></a><h3><a href="r5rs-Z-H-2.html#%_toc_%_sec_6.2.6">6.2.6&nbsp;&nbsp;Numerical input and output</a></h3><p><p><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(<a name="%_idx_350"></a>number-&gt;string<i> z</i>)</tt>&nbsp;</div><div align=left><u>procedure:</u>&nbsp;&nbsp;<tt>(number-&gt;string<i> z radix</i>)</tt>&nbsp;</div><p><em>R</em><em>a</em><em>d</em><em>i</em><em>x</em> must be an exact integer, either 2, 8, 10, or 16.  If omitted,<em>r</em><em>a</em><em>d</em><em>i</em><em>x</em> defaults to 10.The procedure <tt>number-&gt;string</tt> takes anumber and a radix and returns as a 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -