klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

Numbers.html (33589B)


      1 <html lang="en">
      2 <head>
      3 <title>Numbers - klisp Reference Manual</title>
      4 <meta http-equiv="Content-Type" content="text/html">
      5 <meta name="description" content="klisp Reference Manual">
      6 <meta name="generator" content="makeinfo 4.13">
      7 <link title="Top" rel="start" href="index.html#Top">
      8 <link rel="prev" href="Keyed-Variables.html#Keyed-Variables" title="Keyed Variables">
      9 <link rel="next" href="Strings.html#Strings" title="Strings">
     10 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
     11 <meta http-equiv="Content-Style-Type" content="text/css">
     12 <style type="text/css"><!--
     13   pre.display { font-family:inherit }
     14   pre.format  { font-family:inherit }
     15   pre.smalldisplay { font-family:inherit; font-size:smaller }
     16   pre.smallformat  { font-family:inherit; font-size:smaller }
     17   pre.smallexample { font-size:smaller }
     18   pre.smalllisp    { font-size:smaller }
     19   span.sc    { font-variant:small-caps }
     20   span.roman { font-family:serif; font-weight:normal; } 
     21   span.sansserif { font-family:sans-serif; font-weight:normal; } 
     22 --></style>
     23 <link rel="stylesheet" type="text/css" href="css/style.css">
     24 </head>
     25 <body>
     26 <div class="node">
     27 <a name="Numbers"></a>
     28 <p>
     29 Next:&nbsp;<a rel="next" accesskey="n" href="Strings.html#Strings">Strings</a>,
     30 Previous:&nbsp;<a rel="previous" accesskey="p" href="Keyed-Variables.html#Keyed-Variables">Keyed Variables</a>,
     31 Up:&nbsp;<a rel="up" accesskey="u" href="index.html#Top">Top</a>
     32 <hr>
     33 </div>
     34 
     35 <!-- node-name,  next,  previous,  up -->
     36 <h2 class="chapter">14 Numbers</h2>
     37 
     38 <p><a name="index-numbers-166"></a>
     39 All numbers are immutable, and <code>equal?</code> iff <code>eq?</code>.  The
     40 number type is encapsulated.
     41 
     42 <!-- TODO add more content on numbers -->
     43    <p>The external representation of an undefined number is
     44 <code>#undefined</code>.  The external representation of a real with no
     45 primary value is <code>#real</code> (but this may change in the future, the
     46 report is missing the output representation for reals with no primary
     47 values).  All other rules for externally representing numbers pertain
     48 only to defined numbers with primary values.
     49 
     50    <p>An external representation of a real number consists of optional
     51 radix and/or exactness prefixes, optional sign (<code>+</code> or <code>-</code>),
     52 and magnitude. The radix prefixes are <code>#b</code> (binary), <code>#o</code>
     53 (octal), <code>#d</code> (decimal), and <code>#x</code> (hexadecimal); the default
     54 is decimal.  The exactness prefixes are <code>#e</code> (exact) and
     55 <code>#i</code> (inexact); by default, the number is inexact iff the
     56 magnitude representation uses floating point. If both kinds of
     57 prefixes are used, they may occur in either order. The magnitude is
     58 either <code>infinity</code>; an unsigned integer (nonempty sequence of
     59 digits); a ratio of unsigned integers (two unsigned integers with a
     60 <code>/</code> between, of which the second is non-zero); or a floating
     61 point representation.  If the magnitude is <code>infinity</code>, there must
     62 be an exactness prefix and a sign, and no radix prefix.  Floating
     63 point representation can only be used with decimal radix; it consists
     64 of nonempty integer part, point (<code>.</code>), nonempty fraction part,
     65 and optional exponent part.  The optional exponent part consists of an
     66 exponent letter, and an (optionally signed) integer indicating a power
     67 of ten by which to multiply the magnitude.  The choice of exponent
     68 letter makes no difference in what mathematical number is indicated by
     69 the external representation, but does indicate internal representation
     70 precision. Exponent letters <code>s</code>, <code>f</code>, <code>d</code>, <code>f</code>
     71 indicate preference for successively higher internal precision -
     72 short, float, double, long.  When reading an inexact real number,
     73 exponent letter <code>e</code> accepts the default internal precision, which
     74 must be at least double.  When writeing an inexact real number,
     75 exponent letter <code>e</code> may be used for the default internal
     76 precision, and must be used for any internal number format not
     77 indicated by any of the other exponent letters.  Float and double must
     78 provide, respectively, at least as much precision as IEEE 32-bit and
     79 64-bit floating point standards [IE85].  For example, <code>#i#xa/c</code>
     80 represents an inexact number using hexadecimal notation, with signed
     81 magnitude positive five sixths (ten over twelve).  <code>-3.5l-2</code>
     82 represents an inexact number using decimal notation, with signed
     83 magnitude negative thirty five thousandths, and requested long
     84 precision (which must be at least IEEE 64-bit floating point).  When
     85 reading an external representation of an inexact real, the bounds on
     86 the resulting inexact number are chosen in accordance with the
     87 <!-- TODO add xref -->
     88 narrow-arithmetic keyed dynamic variable.
     89 
     90    <p>NOTE: in klisp, all inexact numbers are stored as IEEE 64-bit floating
     91 point.  No bounding or robustness info is kept.
     92 
     93 <div class="defun">
     94 &mdash; Applicative: <b>number?</b> (<var>number? . objects</var>)<var><a name="index-number_003f-167"></a></var><br>
     95 <blockquote><p>  The primitive type predicate for type number.  <code>number?</code>
     96 returns true iff all the objects in <code>objects</code> are of type number. 
     97 </p></blockquote></div>
     98 
     99 <div class="defun">
    100 &mdash; Applicative: <b>integer?</b> (<var>integer? . objects</var>)<var><a name="index-integer_003f-168"></a></var><br>
    101 <blockquote><p>  The primitive type predicate for number subtype integer. 
    102 <code>integer?</code>  returns true iff all the objects in <code>objects</code>
    103 are of type integer. 
    104 </p></blockquote></div>
    105 
    106 <div class="defun">
    107 &mdash; Applicative: <b>exact-integer?</b> (<var>exact-integer? . objects</var>)<var><a name="index-exact_002dinteger_003f-169"></a></var><br>
    108 <blockquote><p>  The primitive type predicate for number subtype exact integer. 
    109 <code>exact-integer?</code>  returns true iff all the objects in
    110 <code>objects</code> are of type integer and exact.
    111 
    112         <p>SOURCE NOTE: this is from r7rs. 
    113 </p></blockquote></div>
    114 
    115 <div class="defun">
    116 &mdash; Applicative: <b>u8?</b> (<var>u8? . objects</var>)<var><a name="index-u8_003f-170"></a></var><br>
    117 <blockquote><p>The primitive type predicate for number subtype exact integer between
    118 0 and 255.  This is the subtype used in bytevectors.  <code>u8?</code>
    119 returns true iff all the objects in <code>objects</code> are of type
    120 integer, are exact, and lie between 0 and 255 inclusive.
    121 
    122         <p>SOURCE NOTE: this is handy for use with bytevectors. 
    123 </p></blockquote></div>
    124 
    125 <div class="defun">
    126 &mdash; Applicative: <b>rational?</b> (<var>rational? . objects</var>)<var><a name="index-rational_003f-171"></a></var><br>
    127 <blockquote><p>  The primitive type predicate for number subtype rational. 
    128 <code>rational?</code>  returns true iff all the objects in <code>objects</code>
    129 are of type rational. 
    130 </p></blockquote></div>
    131 
    132 <div class="defun">
    133 &mdash; Applicative: <b>real?</b> (<var>real? . objects</var>)<var><a name="index-real_003f-172"></a></var><br>
    134 <blockquote><p>  The primitive type predicate for number subtype real. 
    135 <code>real?</code>  returns true iff all the objects in <code>objects</code>
    136 are of type real. 
    137 </p></blockquote></div>
    138 
    139 <div class="defun">
    140 &mdash; Applicative: <b>finite?</b> (<var>finite? . numbers</var>)<var><a name="index-finite_003f-173"></a></var><br>
    141 <blockquote><p>  Predicate <code>finite?</code> returns true iff all the numbers in
    142 <code>numbers</code> are finite. 
    143 </p></blockquote></div>
    144 
    145 <div class="defun">
    146 &mdash; Applicative: <b>exact?</b> (<var>exact? . numbers</var>)<var><a name="index-exact_003f-174"></a></var><br>
    147 <blockquote><p>  Predicate <code>exact?</code> returns true iff all the numbers in
    148 <code>numbers</code> are exact. 
    149 </p></blockquote></div>
    150 
    151 <div class="defun">
    152 &mdash; Applicative: <b>inexact?</b> (<var>inexact? . numbers</var>)<var><a name="index-inexact_003f-175"></a></var><br>
    153 <blockquote><p>  Predicate <code>inexact?</code> returns true iff all the numbers in
    154 <code>numbers</code> are inexact. 
    155 </p></blockquote></div>
    156 
    157 <div class="defun">
    158 &mdash; Applicative: <b>robust?</b> (<var>robust? . numbers</var>)<var><a name="index-robust_003f-176"></a></var><br>
    159 <blockquote><p>  Predicate <code>robust?</code> returns true iff all the numbers in
    160 <code>numbers</code> are robust. 
    161 </p></blockquote></div>
    162 
    163 <div class="defun">
    164 &mdash; Applicative: <b>undefined?</b> (<var>undefined? . numbers</var>)<var><a name="index-undefined_003f-177"></a></var><br>
    165 <blockquote><p>  Predicate <code>undefined?</code> returns true iff all the numbers in
    166 <code>numbers</code> are undefined. 
    167 </p></blockquote></div>
    168 
    169 <div class="defun">
    170 &mdash; Applicative: <b>=?</b> (<var>=? . numbers</var>)<var><a name="index-g_t_003d_003f-178"></a></var><br>
    171 <blockquote><p>  Applicative <code>=?</code> is a predicate that returns true iff all its
    172 arguments are numerically equal to each other.  If any of its
    173 arguments has no primary value, an error is signaled. 
    174 </p></blockquote></div>
    175 
    176 <div class="defun">
    177 &mdash; Applicative: <b>&lt;?</b> (<var>&lt;? . reals</var>)<var><a name="index-g_t_003c_003f-179"></a></var><br>
    178 &mdash; Applicative: <b>&lt;=?</b> (<var>&lt;=? . reals</var>)<var><a name="index-g_t_003c_003d_003f-180"></a></var><br>
    179 &mdash; Applicative: <b>&gt;?</b> (<var>&gt;? . reals</var>)<var><a name="index-g_t_003e_003f-181"></a></var><br>
    180 &mdash; Applicative: <b>&gt;=?</b> (<var>&gt;=? . reals</var>)<var><a name="index-g_t_003e_003d_003f-182"></a></var><br>
    181 <blockquote><p>  Each of these applicatives is a predicate that returns true iff
    182 every two consecutive elements of <code>reals</code> have primary values in
    183 the order indicated by the name of the applicative.  If any element of
    184 <code>reals</code> has no primary value, an error is signaled. 
    185 </p></blockquote></div>
    186 
    187 <div class="defun">
    188 &mdash; Applicative: <b>+</b> (<var>+ . numbers</var>)<var><a name="index-g_t_002b-183"></a></var><br>
    189 <blockquote><p>  Applicative <code>+</code> returns the sum of the elements of numbers.  If
    190 numbers is empty, the sum of its elements is exact zero.  If a
    191 positive infinity is added to a negative infinity, the result has no
    192 primary value.  If all the elements of a cycle are zero, the sum of
    193 the cycle is zero.  If the acyclic sum of the elements of a cycle
    194 (i.e., the sum of an acyclic list containing just those elements) is
    195 non-zero, the sum of the cycle is positive infinity times the acyclic
    196 sum of the elements.  If the acyclic sum of the elements of a cycle is
    197 zero, but some of the elements of the cycle are non-zero, the sum of
    198 the cycle has no primary value. 
    199 </p></blockquote></div>
    200 
    201 <div class="defun">
    202 &mdash; Applicative: <b>*</b> (<var>* . numbers</var>)<var><a name="index-g_t_002a-184"></a></var><br>
    203 <blockquote><p>  Applicative <code>*</code> returns the product of the elements of numbers. 
    204 If numbers is empty, the product of its elements is exact one.  If an
    205 infinity is multiplied by zero, the result has no primary value.  If
    206 the acyclic product of the elements of a cycle is real greater than
    207 one, the product of the cycle is positive infinity. If all the
    208 elements of a cycle are positive one, the product of the cycle is
    209 positive one.  If the acyclic product of the elements of a cycle is
    210 positive one, but some of the elements of the cycle are not positive
    211 one, the product of the cycle has no primary value.  If the acyclic
    212 product of the elements of a cycle has magnitude less than one, the
    213 product of the cycle is zero.  If the acyclic product of the elements
    214 of a cycle has magnitude greater than or equal to one, and is not
    215 positive real, the product of the cycle has no primary value. 
    216 </p></blockquote></div>
    217 
    218 <div class="defun">
    219 &mdash; Applicative: <b>-</b> (<var>- number . numbers</var>)<var><a name="index-g_t_002d-185"></a></var><br>
    220 <blockquote><p>  <code>numbers</code> should be a nonempty list of numbers.
    221 
    222         <p>Applicative <code>-</code> returns the sum of <code>number</code> with the
    223 negation of the sum of <code>numbers</code>. 
    224 </p></blockquote></div>
    225 
    226 <div class="defun">
    227 &mdash; Applicative: <b>zero?</b> (<var>zero? . numbers</var>)<var><a name="index-zero_003f-186"></a></var><br>
    228 <blockquote><p>  Applicative <code>zero?</code> is a predicate that returns true iff every
    229 element of <code>numbers</code> is zero.  For this purpose, a real number is
    230 zero if its primary value is zero.  If any element of numbers has no
    231 primary value an error is signaled. 
    232 </p></blockquote></div>
    233 
    234 <div class="defun">
    235 &mdash; Applicative: <b>div</b> (<var>div real1 real2</var>)<var><a name="index-div-187"></a></var><br>
    236 &mdash; Applicative: <b>mod</b> (<var>mod real1 real2</var>)<var><a name="index-mod-188"></a></var><br>
    237 &mdash; Applicative: <b>div-and-mod</b> (<var>div-and-mod real1 real2</var>)<var><a name="index-div_002dand_002dmod-189"></a></var><br>
    238 <blockquote><p>  For all three applicatives, if <code>real1</code> is infinite or
    239 <code>real2</code> is zero, an error is signaled.
    240 
    241         <p>Let <code>n</code> be the greatest integer such that <code>real2 * n &lt;=
    242 real1</code>.  Applicative <code>div</code> returns <code>n</code>.  Applicative
    243 <code>mod</code> returns <code>real1 - (real2 * n)</code>.  Applicative
    244 <code>div-and-mod</code> returns a freshly allocated list of length two,
    245 whose first element is <code>n</code> and whose second element is
    246 <code>real1 - (real2 * n)</code>.
    247 
    248         <p>NOTE: I'm not really sure about this description... 
    249 </p></blockquote></div>
    250 
    251 <div class="defun">
    252 &mdash; Applicative: <b>div0</b> (<var>div0 real1 real2</var>)<var><a name="index-div0-190"></a></var><br>
    253 &mdash; Applicative: <b>mod0</b> (<var>mod0 real1 real2</var>)<var><a name="index-mod0-191"></a></var><br>
    254 &mdash; Applicative: <b>div0-and-mod0</b> (<var>div0-and-mod0 real1 real2</var>)<var><a name="index-div0_002dand_002dmod0-192"></a></var><br>
    255 <blockquote><p>  For all three applicatives, if <code>real1</code> is infinite or
    256 <code>real2</code> is zero, an error is signaled.
    257 
    258         <p>Let <code>n</code> be the greatest integer such that <code>real2 * n &lt;=
    259 real1 + |real2/2|</code>.  Applicative <code>div0</code> returns <code>n</code>. 
    260 Applicative <code>mod0</code> returns <code>real1 - (real2 * n)</code>. 
    261 Applicative <code>div0-and-mod0</code> returns a freshly allocated list of
    262 length two, whose first element is <code>n</code> and whose second element
    263 is <code>real1 - (real2 * n)</code>.
    264 
    265         <p>NOTE: I'm not really sure about this description... 
    266 </p></blockquote></div>
    267 
    268 <div class="defun">
    269 &mdash; Applicative: <b>positive?</b> (<var>positive? . reals</var>)<var><a name="index-positive_003f-193"></a></var><br>
    270 &mdash; Applicative: <b>negative?</b> (<var>negative? . reals</var>)<var><a name="index-negative_003f-194"></a></var><br>
    271 <blockquote><p>  Applicative <code>positive?</code> is a predicate that returns true iff
    272 every element of <code>reals</code> is greater than zero. Applicative
    273 <code>negative?</code> is a predicate that returns true iff every element of
    274 <code>reals</code> is less than zero.  If any argument to either applicative
    275 has no primary value an error is signaled. 
    276 </p></blockquote></div>
    277 
    278 <div class="defun">
    279 &mdash; Applicative: <b>odd?</b> (<var>odd? . integers</var>)<var><a name="index-odd_003f-195"></a></var><br>
    280 &mdash; Applicative: <b>even?</b> (<var>even? . integers</var>)<var><a name="index-even_003f-196"></a></var><br>
    281 <blockquote><p>  Applicative <code>odd?</code> is a predicate that returns true iff every
    282 element of <code>integers</code> is odd.  Applicative <code>even?</code> is a
    283 predicate that returns true iff every element of <code>integers</code> is
    284 even.  If any argument to either applicative has no primary value an
    285 error is signaled. 
    286 </p></blockquote></div>
    287 
    288 <div class="defun">
    289 &mdash; Applicative: <b>abs</b> (<var>abs real</var>)<var><a name="index-abs-197"></a></var><br>
    290 <blockquote><p>  Applicative <code>abs</code> returns the nonnegative real number with the
    291 same magnitude as <code>real</code>; that is, if <code>real</code> is nonnegative
    292 it returns <code>real</code>, otherwise it returns the negation of
    293 <code>real</code>. 
    294 </p></blockquote></div>
    295 
    296 <div class="defun">
    297 &mdash; Applicative: <b>max</b> (<var>max . reals</var>)<var><a name="index-max-198"></a></var><br>
    298 &mdash; Applicative: <b>min</b> (<var>min . reals</var>)<var><a name="index-min-199"></a></var><br>
    299 <blockquote><p>  If <code>reals</code> is nil, applicative <code>max</code> returns exact
    300 negative infinity, and applicative <code>min</code> returns exact positive
    301 infinity.  If <code>reals</code> is non-nil, applicative <code>max</code> returns
    302 the largest number in <code>reals</code>, and applicative <code>min</code> returns
    303 the smallest number in <code>reals</code>. 
    304 </p></blockquote></div>
    305 
    306 <div class="defun">
    307 &mdash; Applicative: <b>lcm</b> (<var>lcm . impints</var>)<var><a name="index-lcm-200"></a></var><br>
    308 &mdash; Applicative: <b>gcd</b> (<var>gcd . impints</var>)<var><a name="index-gcd-201"></a></var><br>
    309 <blockquote><p>  <code>impints</code> should be a list of improper integers, that is, real
    310 numbers each of which is either an integer or an infinity.
    311 
    312         <p>Applicative <code>lcm</code> returns the smallest positive improper
    313 integer that is an improper0integer multiple of every element of
    314 <code>impints</code> (that is, smallest <code>n &gt;= 1</code> such that for every
    315 argument <code>nk</code> there exists <code>n'k</code> with <code>nk * n'k = n</code>). 
    316 If any of the arguments is zero, the result of <code>lcm</code> has no
    317 primary value.  According to these rules, <code>lcm</code> with nil argument
    318 list returns <code>1</code>, and <code>lcm</code> with any infinite argument
    319 returns positive infinity.
    320 
    321         <p>Applicative <code>gcd</code> returns the largest positive improper integer
    322 such that every element of <code>impints</code> is an improper-integer
    323 multiple of it (that is, largest <code>n &gt;= 1</code> such that for every
    324 argument <code>nk</code> there exists <code>n'k</code> with <code>n * n'k = nk</code>). 
    325 <code>gcd</code> with nil argument list returns exact positive infinity.  If
    326 <code>gcd</code> is called with one or more arguments, and at least one of
    327 the arguments is zero, but none of the arguments is a non-zero finite
    328 integer, its result has no primary value.  According to these rules,
    329 if <code>gcd</code> is called with at least one finite non-zero argument,
    330 its result is the same as if all zero and infinite arguments were
    331 deleted. 
    332 </p></blockquote></div>
    333 
    334 <div class="defun">
    335 &mdash; Applicative: <b>get-real-internal-bounds</b> (<var>get-real-internal-bounds real</var>)<var><a name="index-get_002dreal_002dinternal_002dbounds-202"></a></var><br>
    336 &mdash; Applicative: <b>get-real-exact-bounds</b> (<var>get-real-exact-bounds real</var>)<var><a name="index-get_002dreal_002dexact_002dbounds-203"></a></var><br>
    337 <blockquote><p>  Applicative <code>get-real-internal-bounds</code> returns a freshly
    338 allocated list of reals <code>(x1 x2)</code>, where the primary value of
    339 <code>x1</code> is the lower bound of <code>real</code>, using the same internal
    340 representation as the primary value of <code>real</code>, and the primary
    341 value of <code>x2</code> is the upper bound of <code>real</code>, using the same
    342 internal representation as the primary value of <code>real</code>.  The
    343 <code>xk</code> are inexact iff real is inexact.  The <code>xk</code> are robust
    344 (i.e., tagged if the implementation supports such), and the bounds of
    345 each <code>xk</code> are only required to contain its primary value (i.e.,
    346 the implementation is allowed to make the bounds equal to the primary
    347 value).
    348 
    349         <p>Applicative <code>get-real-exact-bounds</code> returns a freshly allocated
    350 list of exact reals <code>(x1 x2)</code>, where <code>x1</code> is not greater
    351 than the lower bound of <code>real</code>, and <code>x2</code> is not less than
    352 the upper bound of <code>real</code>. 
    353 </p></blockquote></div>
    354 
    355 <div class="defun">
    356 &mdash; Applicative: <b>get-real-internal-primary</b> (<var>get-real-internal-primary real</var>)<var><a name="index-get_002dreal_002dinternal_002dprimary-204"></a></var><br>
    357 &mdash; Applicative: <b>get-real-exact-primary</b> (<var>get-real-exact-primary real</var>)<var><a name="index-get_002dreal_002dexact_002dprimary-205"></a></var><br>
    358 <blockquote><p>  If <code>real</code> is exact, both applicatives return <code>real</code>.  If
    359 <code>real</code> has no primary value, both applicatives signal an error.
    360 
    361         <p>If <code>real</code> is inexact with a primary value, applicative
    362 <code>get-real-internal-primary</code> returns a real number <code>x0</code> whose
    363 primary value is the same as, and has the same internal format as, the
    364 primary value of <code>real</code>.  <code>x0</code> is robust, and its bounds are
    365 only required to contain its primary value.
    366 
    367      <!-- TODO add xref to get-real-exact-bounds -->
    368         <p>If <code>real</code> is inexact with a primary value, applicative
    369 <code>get-real-exact-primary</code> returns an exact real number <code>x0</code>
    370 within the exact bounds that would be returned for <code>real</code> by
    371 applicative <code>get-real-exact-bounds</code>.  Preferably, <code>x0</code>
    372 should be as close to the primary value of <code>real</code> as the
    373 implementation can reasonably arrange. If the implementation does not
    374 support any exact <code>real</code> that reasonably approximates
    375 <code>real</code>, an error may be signaled. 
    376 </p></blockquote></div>
    377 
    378 <div class="defun">
    379 &mdash; Applicative: <b>make-inexact</b> (<var>make-inexact real1 real2 real3</var>)<var><a name="index-make_002dinexact-206"></a></var><br>
    380 <blockquote><p>  Applicative <code>make-inexact</code> returns an inexact real number, as
    381 follows.  If <code>real2</code> is inexact, the result has the same primary
    382 value as <code>real2</code>; and if <code>real2</code> has no primary value, the
    383 result has no primary value.  The result has the same robustness as
    384 <code>real2</code>.  If possible, the result uses the same internal
    385 representation as <code>real2</code>.  If <code>real2</code> is exact, the primary
    386 value of the result is as close to <code>real2</code> as the implementation
    387 can reasonably arrange; overflow and underflow are handled as
    388 <!-- TODO add xref to overflow -->
    389 described in ....  The lower bound of the result is no greater than
    390 the lower bound of <code>real1</code>, the primary value of <code>real2</code>,
    391 and the primary value of the result.  The upper bound of the result is
    392 no less than the upper bound of <code>real3</code>, the primary value of
    393 <code>real2</code>, and the primary value of the result. 
    394 </p></blockquote></div>
    395 
    396 <div class="defun">
    397 &mdash; Applicative: <b>real-&gt;inexact</b> (<var>real-&gt;inexact real</var>)<var><a name="index-real_002d_003einexact-207"></a></var><br>
    398 &mdash; Applicative: <b>real-&gt;exact</b> (<var>real-&gt;exact real</var>)<var><a name="index-real_002d_003eexact-208"></a></var><br>
    399 <blockquote><!-- TODO add xref to get-real-exact-primary -->
    400         <p>Applicative <code>real-&gt;exact</code> behaves just as
    401 <code>get-real-exact-primary</code>.
    402 
    403         <p>If <code>real</code> is inexact, applicative <code>real-&gt;inexact</code> returns
    404 <code>real</code>.  If <code>real</code> is exact, applicative
    405 <code>real-&gt;inexact</code> returns an inexact real <code>x0</code> such that
    406 <code>real</code> would be a permissible result of passing <code>x0</code> to
    407 <code>real-&gt;exact</code>.  If the implementation does not support any such
    408 <code>x0</code>, an error may be signaled.  Otherwise, <code>x0</code> is robust,
    409 and its bounds are only required to contain its primary value and
    410 <code>real</code>. 
    411 </p></blockquote></div>
    412 
    413 <div class="defun">
    414 &mdash; Applicative: <b>with-strict-arithmetic</b> (<var>with-strict-arithmetic boolean combiner</var>)<var><a name="index-with_002dstrict_002darithmetic-209"></a></var><br>
    415 &mdash; Applicative: <b>get-string-arithmetic</b> (<var>get-strict-arithmetic?</var>)<var><a name="index-get_002dstring_002darithmetic-210"></a></var><br>
    416 <blockquote><!-- TODO add xref to dynamic keys and under/over flow, no prim value -->
    417         <p>These applicatives are the binder and accessor of the
    418 <code>strict-arithmetic</code> keyed dynamic variable.  When this keyed
    419 variable is true, various survivable but dubious arithmetic events
    420 signal an error - notably, operation results with no primary value,
    421 and over- and underflows. 
    422 </p></blockquote></div>
    423 
    424 <div class="defun">
    425 &mdash; Applicative: <b>/</b> (<var>/ number . numbers</var>)<var><a name="index-g_t_002f-211"></a></var><br>
    426 <blockquote><p>  <code>numbers</code> should be a nonempty list of numbers.
    427 
    428         <p>Applicative <code>/</code> returns <code>number</code> divided by the product of
    429 <code>numbers</code>.  If the product of <code>numbers</code> is zero, an error is
    430 signaled.  If <code>number</code> is infinite and the product of <code>numbers</code> is
    431 infinite, an error is signaled. 
    432 </p></blockquote></div>
    433 
    434 <div class="defun">
    435 &mdash; Applicative: <b>numerator</b> (<var>numerator rational</var>)<var><a name="index-numerator-212"></a></var><br>
    436 &mdash; Applicative: <b>denominator</b> (<var>denominator rational</var>)<var><a name="index-denominator-213"></a></var><br>
    437 <blockquote><p>  These applicatives return the numerator and denominator of
    438 <code>rational</code>, in least terms (i.e., chosen for the least positive
    439 denominator).  Note that if <code>rational</code> is inexact, and either of
    440 its bounds is not its primary value, the denominator has upper bound
    441 positive infinity, and the numerator must have at least one infinite
    442 bound (two infinite bounds if the bounds of rational allow values of
    443 both signs). 
    444 </p></blockquote></div>
    445 
    446 <div class="defun">
    447 &mdash; Applicative: <b>floor</b> (<var>floor real</var>)<var><a name="index-floor-214"></a></var><br>
    448 &mdash; Applicative: <b>ceiling</b> (<var>ceiling real</var>)<var><a name="index-ceiling-215"></a></var><br>
    449 &mdash; Applicative: <b>truncate</b> (<var>truncate real</var>)<var><a name="index-truncate-216"></a></var><br>
    450 &mdash; Applicative: <b>round</b> (<var>round real</var>)<var><a name="index-round-217"></a></var><br>
    451 <blockquote><p>  Applicative <code>floor</code> returns the largest integer not greater
    452 than <code>real</code>.
    453 
    454         <p>Applicative <code>ceiling</code> returns the smallest integer not less
    455 than <code>real</code>.
    456 
    457         <p>Applicative <code>truncate</code> returns the integer closest to
    458 <code>real</code> whose absolute value is not greater than that of
    459 <code>real</code>.
    460 
    461         <p>Applicative <code>round</code> returns the closest integer to <code>real</code>,
    462 rounding to even when <code>real</code> is halfway between two integers. 
    463 </p></blockquote></div>
    464 
    465 <div class="defun">
    466 &mdash; Applicative: <b>rationalize</b> (<var>rationalize real1 real2</var>)<var><a name="index-rationalize-218"></a></var><br>
    467 &mdash; Applicative: <b>simplest-rational</b> (<var>simplest-rational real1 real2</var>)<var><a name="index-simplest_002drational-219"></a></var><br>
    468 <blockquote><p>  A rational number <code>r1</code> is simpler than another rational
    469 <code>r2</code> if <code>r1 = p1 / q1</code> and <code>r2 = p2 / q2</code>, both in
    470 lowest terms, and <code>|p1| &lt;= |p2|</code> and <code>|q1| &lt;= |q2|</code>. Thus
    471 <code>3/5</code> is simpler than <code>4/7</code>. Not all rationals are
    472 comparable in this ordering, as for example <code>2/7</code> and <code>3/5</code>. 
    473 However, any interval (that contains rational numbers) contains a
    474 rational number that is simpler than every other rational number in
    475 that interval.  Note that <code>0 = 0/1</code> is simpler than any other
    476 rational (so that one never has to choose between <code>p/q</code> and
    477 <code>−p/q</code>).
    478 
    479         <p>For applicative <code>simplest-rational</code>, let <code>x0</code> be the
    480 simplest rational mathematically not less than the primary value of
    481 <code>real1</code> and not greater than the primary value of <code>real2</code>. 
    482 If no such <code>x0</code> exists (because the primary value of <code>real1</code>
    483 is greater, or because the primary values of the arguments are equal
    484 and irrational), or if either argument does not have a primary value,
    485 an error is signaled.
    486 
    487         <p>For applicative <code>rationalize</code>, let <code>x0</code> be the simplest
    488 rational mathematical number within the interval bounded by the
    489 primary value of <code>real1</code> plus and minus the primary value of
    490 <code>real2</code>.  If no such <code>x0</code> exists (because the primary value
    491 of <code>real1</code> is irrational and the primary value <code>real2</code> is
    492 zero), or if either argument does not have a primary value, an error
    493 is signaled.
    494 
    495      <!-- TODO add xref to real->inexact -->
    496         <p>If <code>real1</code> and <code>real2</code> are exact, the applicative
    497 (whichever it is) returns exact <code>x0</code>.  If one or both of
    498 <code>real1</code> and <code>real2</code> are inexact, the applicative returns an
    499 inexact rational approximating <code>x0</code> (as by <code>real-&gt;inexact</code>. 
    500 Note that an inexact result returned is not necessarily bounded by the
    501 primary values of the arguments; but the result is an approximation of
    502 <code>x0</code>, which is so bounded, and the bounds of the result include
    503 <code>x0</code>. 
    504 </p></blockquote></div>
    505 
    506 <div class="defun">
    507 &mdash; Applicative: <b>sqrt</b> (<var>sqrt number</var>)<var><a name="index-sqrt-220"></a></var><br>
    508 <blockquote><p>If <code>number</code> is negative, the result is undefined.
    509 
    510         <p>Applicative <code>sqrt</code> returns the positive square root of number. 
    511 The result may be inexact even if <code>number</code> is exact and the
    512 square root is rational. 
    513 </p></blockquote></div>
    514 
    515 <div class="defun">
    516 &mdash; Applicative: <b>expt</b> (<var>expt number1 number2</var>)<var><a name="index-expt-221"></a></var><br>
    517 <blockquote><p>Applicative <code>expt</code> returns <code>number1</code> to the power of
    518 <code>number2</code>.  If <code>number1</code> is zero, then the result is 1 if
    519 <code>number2</code> is zero and 0 otherwise. 
    520 </p></blockquote></div>
    521 
    522 <div class="defun">
    523 &mdash; Applicative: <b>exp</b> (<var>exp number</var>)<var><a name="index-exp-222"></a></var><br>
    524 &mdash; Applicative: <b>log</b> (<var>log number</var>)<var><a name="index-log-223"></a></var><br>
    525 &mdash; Applicative: <b>sin</b> (<var>sin number</var>)<var><a name="index-sin-224"></a></var><br>
    526 &mdash; Applicative: <b>cos</b> (<var>cos number</var>)<var><a name="index-cos-225"></a></var><br>
    527 &mdash; Applicative: <b>tan</b> (<var>tan number</var>)<var><a name="index-tan-226"></a></var><br>
    528 &mdash; Applicative: <b>asin</b> (<var>asin number</var>)<var><a name="index-asin-227"></a></var><br>
    529 &mdash; Applicative: <b>acos</b> (<var>acos number</var>)<var><a name="index-acos-228"></a></var><br>
    530 &mdash; Applicative: <b>atan</b> (<var>atan number1 </var>[<var>number2</var>])<var><a name="index-atan-229"></a></var><br>
    531 <blockquote><p>These applicatives compute the usual transcendental functions. 
    532 <code>log</code> computes the natural logarithm (not the base-10 logarithm). 
    533 The two argument version of <code>atan</code> computes <code>(angle
    534 (make-recutangular number1 number2))</code> even thou klisp doesn't support
    535 complex numbers.
    536 
    537         <p>All results may be inexact even if <code>number</code> is exact and the
    538 result of the transcendental function is rational. 
    539 TODO add intervals returned for multidefined functions (inverses and log)
    540 </p></blockquote></div>
    541 
    542 <div class="defun">
    543 &mdash; Applicative: <b>string-&gt;number</b> (<var>string-&gt;number string </var>[<var>radix</var>])<var><a name="index-string_002d_003enumber-230"></a></var><br>
    544 <blockquote><p><code>radix</code> should be an exact integer, either 2, 8, 10, or 16. 
    545 <code>string</code> should be a string describing a number in the specified
    546 radix, but may contain a radix prefix to override it.  The default
    547 <code>radix</code>, if not supplied, is 10.
    548 
    549         <p>Applicative <code>string-&gt;number</code> returns the best approximation of
    550 the number represented by <code>string</code>.  If <code>string</code> is not a
    551 valid representation of a number in the given <code>radix</code> an error is
    552 signaled.
    553 
    554         <p>Examples:
    555      <pre class="example">          (string-&gt;number "100") &rArr; 100
    556           (string-&gt;number "100" 16) &rArr; 256
    557           (string-&gt;number "#o100" 2) &rArr; 64
    558           (string-&gt;number "1.0") &rArr; 1.0
    559 </pre>
    560         <p>SOURCE NOTE: this is taken from r7rs. 
    561 </p></blockquote></div>
    562 
    563 <div class="defun">
    564 &mdash; Applicative: <b>number-&gt;string</b> (<var>number-&gt;string number </var>[<var>radix</var>])<var><a name="index-number_002d_003estring-231"></a></var><br>
    565 <blockquote><p><code>radix</code> should be an exact integer, either 2, 8, 10, or 16.  The
    566 default <code>radix</code>, if not supplied, is 10.
    567 
    568         <p>Applicative <code>number-&gt;string</code> returns a string representing
    569 <code>number</code> in the given <code>radix</code>.  No radix prefix is present
    570 in the returned string.  If an inexact number is passed together with
    571 a radix other from 10, an error is signaled.
    572 
    573         <p>The returned string is such that
    574      <pre class="example">          (string-&gt;number (number-&gt;string number radix) radix) == number
    575 </pre>
    576         <p>Examples:
    577      <pre class="example">          (number-&gt;string 100) &rArr; "100"
    578           (number-&gt;string 256 16) &rArr; "100"
    579           (number-&gt;string 1.0) &rArr; "1.0"
    580 </pre>
    581         <p>SOURCE NOTE: this is taken from r7rs. 
    582 </p></blockquote></div>
    583 
    584 <!-- *-texinfo-*- -->
    585    </body></html>
    586