📄 r5rs-z-h-9.html
字号:
<div align=left><u>procedure:</u> <tt>(<a name="%_idx_306"></a>truncate<i> x</i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_308"></a>round<i> x</i>)</tt> </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 <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: </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: </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->exact</tt> procedure.</blockquote><p><tt><p>(floor -4.3) ===> -5.0<br>(ceiling -4.3) ===> -4.0<br>(truncate -4.3) ===> -4.0<br>(round -4.3) ===> -4.0<br><br>(floor 3.5) ===> 3.0<br>(ceiling 3.5) ===> 4.0<br>(truncate 3.5) ===> 3.0<br>(round 3.5) ===> 4.0 ; inexact<br><br>(round 7/2) ===> 4 ; exact<br>(round 7) ===> 7<p></tt><p><p><p><p><div align=left><u>library procedure:</u> <tt>(<a name="%_idx_310"></a>rationalize<i> x y</i>)</tt> </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><</u> |<em>p</em><sub>2</sub>| and |<em>q</em><sub>1</sub>| <u><</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> (inexact->exact .3) 1/10) ===> 1/3 ; exact<br>(rationalize .3 1/10) ===> #i1/3 ; inexact<p></tt><p><p><p><p><div align=left><u>procedure:</u> <tt>(<a name="%_idx_314"></a>exp<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_316"></a>log<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_318"></a>sin<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_320"></a>cos<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_322"></a>tan<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_324"></a>asin<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_326"></a>acos<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_328"></a>atan<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(atan<i> <em>y</em> <em>x</em></i>)</tt> </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æ:<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 [<a href="r5rs-Z-H-14.html#%_sec_7.3">27</a>], which in turncites [<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> <tt>(<a name="%_idx_330"></a>sqrt<i> <em>z</em></i>)</tt> </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> <tt>(<a name="%_idx_332"></a>expt<i> <em>z</em><sub>1</sub> <em>z</em><sub>2</sub></i>)</tt> </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> <tt>(<a name="%_idx_334"></a>make-rectangular<i> <em>x</em><sub>1</sub> <em>x</em><sub>2</sub></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_336"></a>make-polar<i> <em>x</em><sub>3</sub> <em>x</em><sub>4</sub></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_338"></a>real-part<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_340"></a>imag-part<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_342"></a>magnitude<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_344"></a>angle<i> <em>z</em></i>)</tt> </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> · <em>e</em><sup><em>i</em> <em>x</em><sub>4</sub></sup></td></tr></table></div><p>Then<tt><p>(make-rectangular <em>x</em><sub>1</sub> <em>x</em><sub>2</sub>) ===> <em>z</em><br>(make-polar <em>x</em><sub>3</sub> <em>x</em><sub>4</sub>) ===> <em>z</em><br>(real-part <em>z</em>) ===> <em>x</em><sub>1</sub><br>(imag-part <em>z</em>) ===> <em>x</em><sub>2</sub><br>(magnitude <em>z</em>) ===> |<em>x</em><sub>3</sub>|<br>(angle <em>z</em>) ===> <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"> < <em>x</em><sub><em>a</em><em>n</em><em>g</em><em>l</em><em>e</em></sub> <u><</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: </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> <tt>(<a name="%_idx_346"></a>exact->inexact<i> <em>z</em></i>)</tt> </div><div align=left><u>procedure:</u> <tt>(<a name="%_idx_348"></a>inexact->exact<i> <em>z</em></i>)</tt> </div><p><tt>Exact->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->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 <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 Numerical input and output</a></h3><p><p><div align=left><u>procedure:</u> <tt>(<a name="%_idx_350"></a>number->string<i> z</i>)</tt> </div><div align=left><u>procedure:</u> <tt>(number->string<i> z radix</i>)</tt> </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->string</tt> takes anumber and a radix and returns as a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -