Numerical-input-and-output.xhtml 5.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  3. <head>
  4. <title>Numerical input and output</title>
  5. <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
  6. <link rel="stylesheet" type="text/css" href="kawa.css"/>
  7. <script src="kawa-ebook.js" type="text/javascript"/>
  8. <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
  9. <link rel="prev" href="Arithmetic-operations.xhtml" title="Arithmetic operations"/>
  10. <link rel="next" href="Quaternions.xhtml" title="Quaternions"/>
  11. </head>
  12. <body>
  13. <header/>
  14. <section class="sect1" title="Numerical input and output" epub:type="subchapter" id="Numerical-input-and-output">
  15. <div class="titlepage">
  16. <div>
  17. <div>
  18. <h2 class="title" style="clear: both">Numerical input and output</h2>
  19. </div>
  20. </div>
  21. </div>
  22. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876803392" class="indexterm"/> <code class="function">number-&gt;string</code> <em class="replaceable"><code>z</code></em> [<em class="replaceable"><code>radix</code></em>]</p>
  23. <div class="blockquote">
  24. <blockquote class="blockquote">
  25. <p>The procedure <code class="literal">number-&gt;string</code> takes a number and a
  26. radix and returns as a string an external representation
  27. of the given number in the given radix such that
  28. </p>
  29. <pre class="screen">(let ((number number)
  30. (radix radix))
  31. (eqv? number
  32. (string-&gt;number (number-&gt;string number radix)
  33. radix)))
  34. </pre>
  35. <p>is true. It is an error if no possible result makes this expression true.
  36. </p>
  37. <p>If present, <em class="replaceable"><code>radix</code></em> must be an exact integer
  38. in the range 2 to 36, inclusive.
  39. If omitted, <em class="replaceable"><code>radix</code></em> defaults to 10.
  40. </p>
  41. <p>If <em class="replaceable"><code>z</code></em> is inexact, the <em class="replaceable"><code>radix</code></em> is 10, and the above expression
  42. can be satisfied by a result that contains a decimal point,
  43. then the result contains a decimal point and is expressed
  44. using the minimum number of digits (exclusive of exponent
  45. and trailing zeroes) needed to make the above expression;
  46. otherwise the format of the result is unspecified.
  47. </p>
  48. <p>The result returned by <code class="literal">number-&gt;string</code> never contains an
  49. explicit radix prefix.
  50. </p>
  51. <p><span class="emphasis"><em>Note:</em></span>
  52. The error case can occur only when <em class="replaceable"><code>z</code></em> is not a complex
  53. number or is a complex number with a non-rational real or
  54. imaginary part.
  55. </p>
  56. <p><span class="emphasis"><em>Rationale:</em></span> If <em class="replaceable"><code>z</code></em> is an inexact number and the <em class="replaceable"><code>radix</code></em> is 10,
  57. then the above expression is normally satisfied by a result containing
  58. a decimal point. The unspecified case allows for infinities, NaNs,
  59. and unusual representations.
  60. </p>
  61. </blockquote>
  62. </div>
  63. <p class="synopsis" kind="Procedure"><span class="kind">Procedure</span><span class="ignore">: </span><a id="idm139667876790832" class="indexterm"/> <code class="function">string-&gt;number</code> <em class="replaceable"><code>string</code></em> [<em class="replaceable"><code>radix</code></em>]</p>
  64. <div class="blockquote">
  65. <blockquote class="blockquote">
  66. <p>Returns a number of the maximally precise representation
  67. expressed by the given <em class="replaceable"><code>string</code></em>. It is an error if <em class="replaceable"><code>radix</code></em> is not
  68. an exact integer in the range 2 to 26, inclusive.
  69. </p>
  70. <p>If supplied, <em class="replaceable"><code>radix</code></em> is a default radix that will be overridden
  71. if an explicit radix prefix is present in the string (e.g.
  72. <code class="literal">"#o177"</code>). If <em class="replaceable"><code>radix</code></em> is not supplied, then the default <em class="replaceable"><code>radix</code></em>
  73. is 10. If <em class="replaceable"><code>string</code></em> is not a syntactically valid notation for a
  74. number, or would result in a number that the implementation cannot represent,
  75. then <code class="literal">string-&gt;number</code> returns <code class="literal">#f</code>.
  76. An error is never signaled due to the content of <em class="replaceable"><code>string</code></em>.
  77. </p>
  78. <pre class="screen">(string-&gt;number "100") ⇒ 100
  79. (string-&gt;number "100" 16) ⇒ 256
  80. (string-&gt;number "1e2") ⇒ 100.0
  81. (string-&gt;number "#x100" 10) ⇒ 256
  82. </pre>
  83. </blockquote>
  84. </div>
  85. </section>
  86. <footer>
  87. <div class="navfooter">
  88. <p>
  89. Up: <a accesskey="u" href="Numbers.xhtml">Quantities and Numbers</a></p>
  90. <p>
  91. Previous: <a accesskey="p" href="Arithmetic-operations.xhtml">Arithmetic operations</a></p>
  92. <p>
  93. Next: <a accesskey="n" href="Quaternions.xhtml">Quaternions</a></p>
  94. </div>
  95. </footer>
  96. </body>
  97. </html>