r7rs-small-texinfo

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs

commit e8714d1b0e495c9c4c2186e3474ad9e64e2ccb57
parent a76250d0b19ba815de41cac37a2390f104cd57e0
Author: Wolfgang Corcoran-Mathe <wcm@sigwinch.xyz>
Date:   Sat,  3 Feb 2024 13:08:15 -0500

Numbers: Reflow & tidy.

Diffstat:
Mdoc/r7rs-small/procedures/numbers.texinfo | 1027++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 523 insertions(+), 504 deletions(-)

diff --git a/doc/r7rs-small/procedures/numbers.texinfo b/doc/r7rs-small/procedures/numbers.texinfo @@ -1,11 +1,11 @@ @node Numbers @section Numbers -It is important to distinguish between mathematical numbers, the Scheme numbers that -attempt to model them, the machine representations used to implement the Scheme -numbers, and notations used to write numbers. This report uses the types number, -complex, real, rational, and integer to refer to both mathematical numbers and Scheme -numbers. +It is important to distinguish between mathematical numbers, the Scheme +numbers that attempt to model them, the machine representations used to +implement the Scheme numbers, and notations used to write numbers. This +report uses the types number, complex, real, rational, and integer to +refer to both mathematical numbers and Scheme numbers. @menu * Numerical types:: @@ -20,8 +20,8 @@ numbers. @node Numerical types @subsection Numerical types -Mathematically, numbers are arranged into a tower of subtypes in which each level is a -subset of the level above it: +Mathematically, numbers are arranged into a tower of subtypes in which +each level is a subset of the level above it: @display number @@ -31,99 +31,105 @@ rational number integer @end display -For example, 3 is an integer. Therefore 3 is also a rational, -a real, and a complex number. The same is true of the Scheme numbers -that model 3. For Scheme numbers, these types are defined by the -predicates @code{number?}, @code{complex?}, @code{real?}, @code{rational?}, -and @code{integer?}. +For example, 3 is an integer. Therefore 3 is also a rational, a real, and +a complex number. The same is true of the Scheme numbers that model 3. For +Scheme numbers, these types are defined by the predicates @code{number?}, +@code{complex?}, @code{real?}, @code{rational?}, and @code{integer?}. -There is no simple relationship between a number's type and its representation inside a -computer. Although most implementations of Scheme will offer at least two different -representations of 3, these different representations denote the same integer. +There is no simple relationship between a number's type and its +representation inside a computer. Although most implementations of Scheme +will offer at least two different representations of 3, these different +representations denote the same integer. -Scheme's numerical operations treat numbers as abstract data, as independent of their -representation as possible. Although an implementation of Scheme may use multiple -internal representations of numbers, this ought not to be apparent to a casual -programmer writing simple programs. +Scheme's numerical operations treat numbers as abstract data, +as independent of their representation as possible. Although an +implementation of Scheme may use multiple internal representations of +numbers, this ought not to be apparent to a casual programmer writing +simple programs. @node Exactness @subsection Exactness -It is useful to distinguish between numbers that are represented exactly and those that -might not be. For example, indexes into data structures must be known exactly, as must -some polynomial coefficients in a symbolic algebra system. On the other hand, the results -of measurements are inherently inexact, and irrational numbers may be approximated by -rational and therefore inexact approximations. In order to catch uses of inexact numbers -where exact numbers are required, Scheme explicitly distinguishes exact from inexact -numbers. This distinction is orthogonal to the dimension of type. - -A Scheme number is -@dfn{exact} if it was written as an exact constant or was derived from -exact numbers using only exact operations. A number is -@dfn{inexact} if it was written as an inexact constant, -if it was +It is useful to distinguish between numbers that are represented exactly +and those that might not be. For example, indexes into data structures +must be known exactly, as must some polynomial coefficients in a +symbolic algebra system. On the other hand, the results of measurements +are inherently inexact, and irrational numbers may be approximated by +rational and therefore inexact approximations. In order to catch uses +of inexact numbers where exact numbers are required, Scheme explicitly +distinguishes exact from inexact numbers. This distinction is orthogonal +to the dimension of type. + +A Scheme number is @dfn{exact} if it was written as an exact constant +or was derived from exact numbers using only exact operations. A number +is @dfn{inexact} if it was written as an inexact constant, if it was derived using @dfn{inexact} ingredients, or if it was derived using -@dfn{inexact} operations. Thus inexactness is a contagious -property of a number. -In particular, an @dfn{exact complex number} has an exact real part -and an exact imaginary part; all other complex numbers are @dfn{inexact -complex numbers}. - -If two implementations produce exact results for a computation that did not involve -inexact intermediate results, the two ultimate results will be mathematically equal. This is -generally not true of computations involving inexact numbers since approximate -methods such as floating-point arithmetic may be used, but it is the duty of each -implementation to make the result as close as practical to the mathematically ideal result. - -Rational operations such as @code{+} should always produce exact results when given exact -arguments. If the operation is unable to produce an exact result, then it may either report -the violation of an implementation restriction or it may silently coerce its result to an -inexact value. However, @code{(/ 3 4)} must not return the mathematically incorrect value @code{0}. -@xref{Implementation restrictions}. - -Except for @code{exact}, the operations described in this section must generally return inexact -results when given any inexact arguments. An operation may, however, return an exact -result if it can prove that the value of the result is unaffected by the inexactness of its -arguments. For example, multiplication of any number by an exact zero may produce an +@dfn{inexact} operations. Thus inexactness is a contagious property of +a number. In particular, an @dfn{exact complex number} has an exact +real part and an exact imaginary part; all other complex numbers are +@dfn{inexact complex numbers}. + +If two implementations produce exact results for a computation that +did not involve inexact intermediate results, the two ultimate results +will be mathematically equal. This is generally not true of computations +involving inexact numbers since approximate methods such as floating-point +arithmetic may be used, but it is the duty of each implementation to +make the result as close as practical to the mathematically ideal result. + +Rational operations such as @code{+} should always produce exact +results when given exact arguments. If the operation is unable to +produce an exact result, then it may either report the violation of an +implementation restriction or it may silently coerce its result to an +inexact value. However, @code{(/ 3 4)} must not return the mathematically +incorrect value @code{0}. @xref{Implementation restrictions}. + +Except for @code{exact}, the operations described in this section must +generally return inexact results when given any inexact arguments. An +operation may, however, return an exact result if it can prove that the +value of the result is unaffected by the inexactness of its arguments. For +example, multiplication of any number by an exact zero may produce an exact zero result, even if the other argument is inexact. -Specifically, the expression @code{(* 0 +inf.0)} may return @code{0}, or @code{+nan.0}, or report that inexact -numbers are not supported, or report that non-rational real numbers are not supported, -or fail silently or noisily in other implementation-specific ways. +Specifically, the expression @code{(* 0 +inf.0)} may return @code{0}, +or @code{+nan.0}, or report that inexact numbers are not supported, +or report that non-rational real numbers are not supported, or fail +silently or noisily in other implementation-specific ways. @node Implementation restrictions @subsection Implementation restrictions -Implementations of Scheme are not required to implement the whole tower of subtypes -given in @ref{Numerical types}, but they must implement a coherent subset consistent with both -the purposes of the implementation and the spirit of the Scheme language. For example, -implementations in which all numbers are real, or in which non-real numbers are always -inexact, or in which exact numbers are always integer, are still quite useful. - -Implementations may also support only a limited range of numbers of any type, subject to -the requirements of this section. The supported range for exact numbers of any type may -be different from the supported range for inexact numbers of that type. For example, an -implementation that uses IEEE binary double-precision floating-point numbers to -represent all its inexact real numbers may also support a practically unbounded range of -exact integers and rationals while limiting the range of inexact reals (and therefore the -range of inexact integers and rationals) to the dynamic range of the IEEE binary double -format. Furthermore, the gaps between the representable inexact integers and rationals -are likely to be very large in such an implementation as the limits of this range are -approached. - -An implementation of Scheme must support exact integers -throughout the range of numbers permitted as indexes of -lists, vectors, bytevectors, and strings or that result from computing the length of -one of these. The @code{length}, @code{vector-length}, -@code{bytevector-length}, and @code{string-length} procedures must return an exact -integer, and it is an error to use anything but an exact integer as an -index. Furthermore, any integer constant within the index range, if -expressed by an exact integer syntax, must be read as an exact -integer, regardless of any implementation restrictions that apply -outside this range. Finally, the procedures listed below will always -return exact integer results provided all their arguments are exact integers -and the mathematically expected results are representable as exact integers -within the implementation: +Implementations of Scheme are not required to implement the whole tower +of subtypes given in @ref{Numerical types}, but they must implement a +coherent subset consistent with both the purposes of the implementation +and the spirit of the Scheme language. For example, implementations +in which all numbers are real, or in which non-real numbers are always +inexact, or in which exact numbers are always integer, are still quite +useful. + +Implementations may also support only a limited range of numbers of any +type, subject to the requirements of this section. The supported range +for exact numbers of any type may be different from the supported range +for inexact numbers of that type. For example, an implementation that uses +IEEE binary double-precision floating-point numbers to represent all its +inexact real numbers may also support a practically unbounded range of +exact integers and rationals while limiting the range of inexact reals +(and therefore the range of inexact integers and rationals) to the dynamic +range of the IEEE binary double format. Furthermore, the gaps between the +representable inexact integers and rationals are likely to be very large +in such an implementation as the limits of this range are approached. + +An implementation of Scheme must support exact integers throughout the +range of numbers permitted as indexes of lists, vectors, bytevectors, and +strings or that result from computing the length of one of these. The +@code{length}, @code{vector-length}, @code{bytevector-length}, and +@code{string-length} procedures must return an exact integer, and it is +an error to use anything but an exact integer as an index. Furthermore, +any integer constant within the index range, if expressed by an exact +integer syntax, must be read as an exact integer, regardless of any +implementation restrictions that apply outside this range. Finally, the +procedures listed below will always return exact integer results provided +all their arguments are exact integers and the mathematically expected +results are representable as exact integers within the implementation: @itemize @w{} @item @@ -209,115 +215,131 @@ within the implementation: @end itemize -It is recommended, but not required, that implementations support exact integers and -exact rationals of practically unlimited size and precision, and to implement the above -procedures and the @code{/} procedure in such a way that they always return exact results when -given exact arguments. If one of these procedures is unable to deliver an exact result -when given exact arguments, then it may either report a violation of an implementation -restriction or it may silently coerce its result to an inexact number; such a coercion can -cause an error later. Nevertheless, implementations that do not provide exact rational +It is recommended, but not required, that implementations support +exact integers and exact rationals of practically unlimited size and +precision, and to implement the above procedures and the @code{/} +procedure in such a way that they always return exact results when +given exact arguments. If one of these procedures is unable to deliver +an exact result when given exact arguments, then it may either report +a violation of an implementation restriction or it may silently coerce +its result to an inexact number; such a coercion can cause an error +later. Nevertheless, implementations that do not provide exact rational numbers should return inexact rational numbers rather than reporting an implementation restriction. -An implementation may use floating-point and other approximate representation -strategies for inexact numbers. This report recommends, but does not require, that -implementations that use floating-point representations follow the IEEE 754 standard, -and that implementations using other representations should match or exceed the -precision achievable using these floating-point standards [17]. In particular, the -description of transcendental functions in IEEE 754-2008 should be followed by such -implementations, particularly with respect to infinities and NaNs. - -Although Scheme allows a variety of written notations for numbers, any particular -implementation may support only some of them. For example, an implementation in -which all numbers are real need not support the rectangular and polar notations for -complex numbers. If an implementation encounters an exact numerical constant that it -cannot represent as an exact number, then it may either report a violation of an -implementation restriction or it may silently represent the constant by an inexact +An implementation may use floating-point and other approximate +representation strategies for inexact numbers. This report recommends, +but does not require, that implementations that use floating-point +representations follow the IEEE 754 standard, and that implementations +using other representations should match or exceed the precision +achievable using these floating-point standards [17]. In particular, +the description of transcendental functions in IEEE 754-2008 should be +followed by such implementations, particularly with respect to infinities +and NaNs. + +Although Scheme allows a variety of written notations for numbers, any +particular implementation may support only some of them. For example, +an implementation in which all numbers are real need not support the +rectangular and polar notations for complex numbers. If an implementation +encounters an exact numerical constant that it cannot represent as an +exact number, then it may either report a violation of an implementation +restriction or it may silently represent the constant by an inexact number. @node Implementation extensions @subsection Implementation extensions -Implementations may provide more than one representation of floating-point numbers -with differing precisions. In an implementation which does so, an inexact result must be -represented with at least as much precision as is used to express any of the inexact -arguments to that operation. Although it is desirable for potentially inexact operations -such as @code{sqrt} to produce exact answers when applied to exact arguments, if an exact -number is operated upon so as to produce an inexact result, then the most precise -representation available must be used. For example, the value of @code{(sqrt 4)} should be @code{2}, but -in an implementation that provides both single and double precision floating point -numbers it may be the latter but must not be the former. - -It is the programmer's responsibility to avoid using inexact number objects with -magnitude or significand too large to be represented in the implementation. - -In addition, implementations may distinguish special numbers called positive infinity, -negative infinity, NaN, and negative zero. - -Positive infinity is regarded as an inexact real (but not rational) number that represents an -indeterminate value greater than the numbers represented by all rational numbers. -Negative infinity is regarded as an inexact real (but not rational) number that represents -an indeterminate value less than the numbers represented by all rational numbers. - -Adding or multiplying an infinite value by any finite real value results in an appropriately -signed infinity; however, the sum of positive and negative infinities is a NaN. Positive -infinity is the reciprocal of zero, and negative infinity is the reciprocal of negative zero. -The behavior of the transcendental functions is sensitive to infinity in accordance with -IEEE 754. - -A NaN is regarded as an inexact real (but not rational) number so indeterminate that it -might represent any real value, including positive or negative infinity, and might even be -greater than positive infinity or less than negative infinity. An implementation that does -not support non-real numbers may use NaN to represent non-real values like @code{(sqrt -1.0)} -and @code{(asin 2.0)}. - -A NaN always compares false to any number, including a NaN. An arithmetic operation -where one operand is NaN returns NaN, unless the implementation can prove that the -result would be the same if the NaN were replaced by any rational number. Dividing zero -by zero results in NaN unless both zeros are exact. - -Negative zero is an inexact real value written @code{-0.0} and is distinct (in the sense of @code{eqv?}) from -@code{0.0}. A Scheme implementation is not required to distinguish negative zero. If it does, -however, the behavior of the transcendental functions is sensitive to the distinction in -accordance with IEEE 754. Specifically, in a Scheme implementing both complex numbers -and negative zero, the branch cut of the complex logarithm function is such that -@code{(imag-part (log -1.0-0.0i))} is @minus{}@greekpi{} rather than @greekpi{}. - -Furthermore, the negation of negative zero is ordinary zero and vice versa. This implies -that the sum of two or more negative zeros is negative, and the result of subtracting -(positive) zero from a negative zero is likewise negative. However, numerical comparisons -treat negative zero as equal to zero. - -Note that both the real and the imaginary parts of a complex number can be infinities, -NaNs, or negative zero. +Implementations may provide more than one representation of floating-point +numbers with differing precisions. In an implementation which does so, an +inexact result must be represented with at least as much precision as is +used to express any of the inexact arguments to that operation. Although +it is desirable for potentially inexact operations such as @code{sqrt} +to produce exact answers when applied to exact arguments, if an exact +number is operated upon so as to produce an inexact result, then the +most precise representation available must be used. For example, the +value of @code{(sqrt 4)} should be @code{2}, but in an implementation +that provides both single and double precision floating point numbers +it may be the latter but must not be the former. + +It is the programmer's responsibility to avoid using inexact number +objects with magnitude or significand too large to be represented in +the implementation. + +In addition, implementations may distinguish special numbers called +positive infinity, negative infinity, NaN, and negative zero. + +Positive infinity is regarded as an inexact real (but not rational) +number that represents an indeterminate value greater than the numbers +represented by all rational numbers. Negative infinity is regarded as an +inexact real (but not rational) number that represents an indeterminate +value less than the numbers represented by all rational numbers. + +Adding or multiplying an infinite value by any finite real value results +in an appropriately signed infinity; however, the sum of positive and +negative infinities is a NaN. Positive infinity is the reciprocal of zero, +and negative infinity is the reciprocal of negative zero. The behavior +of the transcendental functions is sensitive to infinity in accordance +with IEEE 754. + +A NaN is regarded as an inexact real (but not rational) number so +indeterminate that it might represent any real value, including positive +or negative infinity, and might even be greater than positive infinity +or less than negative infinity. An implementation that does not support +non-real numbers may use NaN to represent non-real values like +@code{(sqrt -1.0)} and @code{(asin 2.0)}. + +A NaN always compares false to any number, including a NaN. An arithmetic +operation where one operand is NaN returns NaN, unless the implementation +can prove that the result would be the same if the NaN were replaced by +any rational number. Dividing zero by zero results in NaN unless both +zeros are exact. + +Negative zero is an inexact real value written @code{-0.0} and is distinct +(in the sense of @code{eqv?}) from @code{0.0}. A Scheme implementation +is not required to distinguish negative zero. If it does, however, the +behavior of the transcendental functions is sensitive to the distinction +in accordance with IEEE 754. Specifically, in a Scheme implementing +both complex numbers and negative zero, the branch cut of the complex +logarithm function is such that @code{(imag-part (log -1.0-0.0i))} +is @minus{}@greekpi{} rather than @greekpi{}. + +Furthermore, the negation of negative zero is ordinary zero and vice +versa. This implies that the sum of two or more negative zeros is +negative, and the result of subtracting (positive) zero from a negative +zero is likewise negative. However, numerical comparisons treat negative +zero as equal to zero. + +Note that both the real and the imaginary parts of a complex number can +be infinities, NaNs, or negative zero. @node Syntax of numerical constants @subsection Syntax of numerical constants -The syntax of the written representations for numbers is described formally in -@ref{Formal syntax}. -Note that case is not significant in numerical constants. +The syntax of the written representations for numbers is described +formally in @ref{Formal syntax}. Note that case is not significant in +numerical constants. -A number can be written in binary, octal, decimal, or hexadecimal by the use of a radix -prefix. The radix prefixes are @code{#b} (binary), @code{#o} (octal), @code{#d} (decimal), and @code{#x} (hexadecimal). With +A number can be written in binary, octal, decimal, or hexadecimal by +the use of a radix prefix. The radix prefixes are @code{#b} (binary), +@code{#o} (octal), @code{#d} (decimal), and @code{#x} (hexadecimal). With no radix prefix, a number is assumed to be expressed in decimal. -A numerical constant can be specified to be either exact or inexact by a prefix. The -prefixes are @code{#e} for exact, and @code{#i} for inexact. An exactness prefix can appear before or after -any radix prefix that is used. If the written representation of a number has no exactness -prefix, the constant is inexact if it contains a decimal point or an exponent. Otherwise, it is -exact. - -In systems with inexact numbers of varying precisions it can be useful to specify the -precision of a constant. For this purpose, implementations may accept numerical -constants written with an exponent marker that indicates the desired precision of the -inexact representation. If so, the letter @code{s}, @code{f}, @code{d}, or @code{l}, meaning -@dfn{short}, -@dfn{single}, -@dfn{double}, or -@dfn{long} precision, respectively, can be used in place of @code{e}. The default precision has at least as -much precision as -double, but implementations may allow this default to be set by the user. +A numerical constant can be specified to be either exact or inexact +by a prefix. The prefixes are @code{#e} for exact, and @code{#i} for +inexact. An exactness prefix can appear before or after any radix prefix +that is used. If the written representation of a number has no exactness +prefix, the constant is inexact if it contains a decimal point or an +exponent. Otherwise, it is exact. + +In systems with inexact numbers of varying precisions it can be useful to +specify the precision of a constant. For this purpose, implementations +may accept numerical constants written with an exponent marker that +indicates the desired precision of the inexact representation. If so, the +letter @code{s}, @code{f}, @code{d}, or @code{l}, meaning @dfn{short}, +@dfn{single}, @dfn{double}, or @dfn{long} precision, respectively, can +be used in place of @code{e}. The default precision has at least as much +precision as double, but implementations may allow this default to be +set by the user. @display @code{3.14159265358979F0} @@ -326,35 +348,38 @@ double, but implementations may allow this default to be set by the user. Extend to long --- @code{.600000000000000} @end display -The numbers positive infinity, negative infinity, -and NaN are written @code{+inf.0}, @code{-inf.0} and @dfn{+nan.0} respectively. NaN may also be written @code{-nan.0}. -The use of signs in the written representation does not necessarily reflect the underlying -sign of the NaN value, if any. Implementations are not required to support these -numbers, but if they do, they must do so in general conformance with IEEE 754. However, -implementations are not required to support signaling NaNs, nor to provide a way to -distinguish between different NaNs. - -There are two notations provided for non-real complex numbers: -the @dfn{rectangular notation} -@var{a}@code{+}@var{b}@code{i}, -where @var{a} is the real part and @var{b} is the imaginary part; -and the @dfn{polar notation} -@var{r}@code{@@}@var{@greektheta{}} -where @var{r} is the magnitude and @var{@greektheta{}} is the phase (angle) in radians. -These are related by the equation -@math{a + bi = r \cos\theta + (r \sin\theta)i}. -All of @var{a}, @var{b}, @var{r}, and @var{@greektheta{}} are real numbers. +The numbers positive infinity, negative infinity, and NaN are written +@code{+inf.0}, @code{-inf.0} and @dfn{+nan.0} respectively. NaN may +also be written @code{-nan.0}. The use of signs in the written +representation does not necessarily reflect the underlying sign of the +NaN value, if any. Implementations are not required to support these +numbers, but if they do, they must do so in general conformance with +IEEE 754. However, implementations are not required to support +signaling NaNs, nor to provide a way to distinguish between different +NaNs. + +There are two notations provided for non-real complex numbers: the +@dfn{rectangular notation} @var{a}@code{+}@var{b}@code{i}, where +@var{a} is the real part and @var{b} is the imaginary part; and the +@dfn{polar notation} @var{r}@code{@@}@var{@greektheta{}} where @var{r} +is the magnitude and @var{@greektheta{}} is the phase (angle) in +radians. These are related by the equation +@math{a + bi = r \cos\theta + (r \sin\theta)i}. All of @var{a}, +@var{b}, @var{r}, and @var{@greektheta{}} are real numbers. @node Numerical operations @subsection Numerical operations -The reader is referred to @ref{Error situations and unspecified behavior} for a summary of the naming conventions used to -specify restrictions on the types of arguments to numerical routines. The examples used -in this section assume that any numerical constant written using an exact notation is -indeed represented as an exact number. Some examples also assume that certain -numerical constants written using an inexact notation can be represented without loss of -accuracy; the inexact constants were chosen so that this is likely to be true in -implementations that use IEEE binary doubles to represent inexact numbers. +The reader is referred to @ref{Error situations and unspecified +behavior} for a summary of the naming conventions used to specify +restrictions on the types of arguments to numerical routines. The +examples used in this section assume that any numerical constant +written using an exact notation is indeed represented as an exact +number. Some examples also assume that certain numerical constants +written using an inexact notation can be represented without loss of +accuracy; the inexact constants were chosen so that this is likely to +be true in implementations that use IEEE binary doubles to represent +inexact numbers. @deffn procedure number? obj @deffnx procedure complex? obj @@ -362,70 +387,70 @@ implementations that use IEEE binary doubles to represent inexact numbers. @deffnx procedure rational? obj @deffnx procedure integer? obj -These numerical type predicates can be applied to any kind of -argument, including non-numbers. They return @code{#t} if the object is -of the named type, and otherwise they return @code{#f}. -In general, if a type predicate is true of a number then all higher -type predicates are also true of that number. Consequently, if a type -predicate is false of a number, then all lower type predicates are -also false of that number. +These numerical type predicates can be applied to any kind of argument, +including non-numbers. They return @code{#t} if the object is of the +named type, and otherwise they return @code{#f}. In general, if a type +predicate is true of a number then all higher type predicates are also +true of that number. Consequently, if a type predicate is false of a +number, then all lower type predicates are also false of that number. -If @var{z} is a complex number, then @code{(real? }@var{z}@code{)} is true if -and only if @code{(zero? (imag-part }@var{z}@code{))} is true. -If @var{x} is an inexact real number, then -@code{(integer? }@var{x}@code{)} is true if and only if @code{(= }@var{x}@code{ (round }@var{x}@code{))}. +If @var{z} is a complex number, then @code{(real? }@var{z}@code{)} is +true if and only if @code{(zero? (imag-part }@var{z}@code{))} is true. If +@var{x} is an inexact real number, then @code{(integer? }@var{x}@code{)} +is true if and only if @code{(= }@var{x}@code{ (round }@var{x}@code{))}. -The numbers @code{+inf.0}, @code{-inf.0}, and @code{+nan.0} are real but -not rational. +The numbers @code{+inf.0}, @code{-inf.0}, and @code{+nan.0} are real +but not rational. @lisp -(complex? 3+4i) @result{} #t -(complex? 3) @result{} #t -(real? 3) @result{} #t -(real? -2.5+0i) @result{} #t -(real? -2.5+0.0i) @result{} #f -(real? #e1e10) @result{} #t -(real? +inf.0) @result{} #t -(real? +nan.0) @result{} #t -(rational? -inf.0) @result{} #f -(rational? 3.5) @result{} #t -(rational? 6/10) @result{} #t -(rational? 6/3) @result{} #t -(integer? 3+0i) @result{} #t -(integer? 3.0) @result{} #t -(integer? 8/4) @result{} #t +(complex? 3+4i) @result{} #t +(complex? 3) @result{} #t +(real? 3) @result{} #t +(real? -2.5+0i) @result{} #t +(real? -2.5+0.0i) @result{} #f +(real? #e1e10) @result{} #t +(real? +inf.0) @result{} #t +(real? +nan.0) @result{} #t +(rational? -inf.0) @result{} #f +(rational? 3.5) @result{} #t +(rational? 6/10) @result{} #t +(rational? 6/3) @result{} #t +(integer? 3+0i) @result{} #t +(integer? 3.0) @result{} #t +(integer? 8/4) @result{} #t @end lisp -Note: The behavior of these type predicates on inexact numbers is unreliable, since - any inaccuracy might affect the result. +Note: The behavior of these type predicates on inexact numbers is +unreliable, since any inaccuracy might affect the result. -Note: In many implementations the @code{complex?} procedure will be the same as -@code{number?}, but unusual implementations may represent some irrational numbers -exactly or may extend the number system to support some kind of non-complex -numbers. +Note: In many implementations the @code{complex?} procedure will be the +same as @code{number?}, but unusual implementations may represent some +irrational numbers exactly or may extend the number system to support +some kind of non-complex numbers. @end deffn @deffn procedure exact? z @deffnx procedure inexact? z -These numerical predicates provide tests for the exactness of a quantity. For any Scheme -number, precisely one of these predicates is true. +These numerical predicates provide tests for the exactness of a +quantity. For any Scheme number, precisely one of these predicates is +true. @lisp -(exact? 3.0) @result{} #f -(exact? #e3.0) @result{} #t -(inexact? 3.) @result{} #t +(exact? 3.0) @result{} #f +(exact? #e3.0) @result{} #t +(inexact? 3.) @result{} #t @end lisp @end deffn @deffn procedure exact-integer? z -Returns @code{#t} if @var{z} is both exact and an integer; -otherwise returns @code{#f}. +Returns @code{#t} if @var{z} is both exact and an integer; otherwise +returns @code{#f}. @lisp -(exact-integer? 32) @result{} #t +(exact-integer? 32) @result{} #t (exact-integer? 32.0) @result{} #f (exact-integer? 32/5) @result{} #f @end lisp @@ -433,44 +458,44 @@ otherwise returns @code{#f}. @deffn {inexact library procedure} finite? z -The @code{finite?} procedure returns @code{#t} on all real numbers except -@code{+inf.0}, @code{-inf.0}, and @code{+nan.0}, and on complex -numbers if their real and imaginary parts are both finite. -Otherwise it returns @code{#f}. +The @code{finite?} procedure returns @code{#t} on all real numbers +except @code{+inf.0}, @code{-inf.0}, and @code{+nan.0}, and on complex +numbers if their real and imaginary parts are both finite. Otherwise it +returns @code{#f}. @lisp -(finite? 3) @result{} #t -(finite? +inf.0) @result{} #f -(finite? 3.0+inf.0i) @result{} #f +(finite? 3) @result{} #t +(finite? +inf.0) @result{} #f +(finite? 3.0+inf.0i) @result{} #f @end lisp @end deffn @deffn {inexact library procedure} infinite? z The @code{infinite?} procedure returns @code{#t} on the real numbers -@code{+inf.0} and @code{-inf.0}, and on complex -numbers if their real or imaginary parts or both are infinite. -Otherwise it returns @code{#f}. +@code{+inf.0} and @code{-inf.0}, and on complex numbers if their real +or imaginary parts or both are infinite. Otherwise it returns +@code{#f}. @example -(infinite? 3) @result{} #f -(infinite? +inf.0) @result{} #t -(infinite? +nan.0) @result{} #f -(infinite? 3.0+inf.0i) @result{} #t +(infinite? 3) @result{} #f +(infinite? +inf.0) @result{} #t +(infinite? +nan.0) @result{} #f +(infinite? 3.0+inf.0i) @result{} #t @end example @end deffn @deffn {inexact library procedure} nan? z -The @code{nan?} procedure returns @code{#t} on @code{+nan.0}, and on complex -numbers if their real or imaginary parts or both are @code{+nan.0}. -Otherwise it returns @code{#f}. +The @code{nan?} procedure returns @code{#t} on @code{+nan.0}, and on +complex numbers if their real or imaginary parts or both are +@code{+nan.0}. Otherwise it returns @code{#f}. @example -(nan? +nan.0) @result{} #t -(nan? 32) @result{} #f -(nan? +nan.0+5.0i) @result{} #t -(nan? 1+2i) @result{} #f +(nan? +nan.0) @result{} #t +(nan? 32) @result{} #f +(nan? +nan.0+5.0i) @result{} #t +(nan? 1+2i) @result{} #f @end example @end deffn @@ -481,29 +506,28 @@ Otherwise it returns @code{#f}. @deffnx procedure >= x@sub{1} x@sub{2} x@sub{3}@dots{} These procedures return @code{#t} if their arguments are (respectively): -equal, monotonically increasing, monotonically decreasing, -monotonically non-decreasing, or monotonically non-increasing, -and @code{#f} otherwise. -If any of the arguments are @code{+nan.0}, all the predicates return @code{#f}. -They do not distinguish between inexact zero and inexact negative zero. +equal, monotonically increasing, monotonically decreasing, monotonically +non-decreasing, or monotonically non-increasing, and @code{#f} otherwise. +If any of the arguments are @code{+nan.0}, all the predicates return +@code{#f}. They do not distinguish between inexact zero and inexact +negative zero. These predicates are required to be transitive. -Note: The implementation approach -of converting all arguments to inexact numbers -if any argument is inexact is not transitive. For example, let -@code{big} be @code{(expt 2 1000)}, and assume that @code{big} is exact and that -inexact numbers are represented by 64-bit IEEE binary floating point numbers. -Then @code{(= (- big 1) (inexact big))} and -@code{(= (inexact big) (+ big 1))} would both be true with this approach, -because of the limitations of IEEE -representations of large integers, whereas @code{(= (- big 1) (+ big 1))} -is false. Converting inexact values to exact numbers that are the same (in the sense of @code{=}) to them will avoid -this problem, though special care must be taken with infinities. +Note: The implementation approach of converting all arguments to inexact +numbers if any argument is inexact is not transitive. For example, let +@code{big} be @code{(expt 2 1000)}, and assume that @code{big} is exact +and that inexact numbers are represented by 64-bit IEEE binary floating +point numbers. Then @code{(= (- big 1) (inexact big))} and @code{(= +(inexact big) (+ big 1))} would both be true with this approach, because +of the limitations of IEEE representations of large integers, whereas +@code{(= (- big 1) (+ big 1))} is false. Converting inexact values to +exact numbers that are the same (in the sense of @code{=}) to them will +avoid this problem, though special care must be taken with infinities. Note: While it is not an error to compare inexact numbers using these -predicates, the results are unreliable because a small inaccuracy -can affect the result; this is especially true of @code{=} and @code{zero?}. +predicates, the results are unreliable because a small inaccuracy can +affect the result; this is especially true of @code{=} and @code{zero?}. When in doubt, consult a numerical analyst. @end deffn @@ -514,8 +538,8 @@ When in doubt, consult a numerical analyst. @deffnx procedure odd? n @deffnx procedure even? n -These numerical predicates test a number for a particular property, returning @code{#t} or @code{#f}. -See note above. +These numerical predicates test a number for a particular property, +returning @code{#t} or @code{#f}. See note above. @end deffn @@ -525,16 +549,17 @@ See note above. These procedures return the maximum or minimum of their arguments. @example -(max 3 4) @result{} 4 ; exact -(max 3.9 4) @result{} 4.0 ; inexact +(max 3 4) @result{} 4 ; exact +(max 3.9 4) @result{} 4.0 ; inexact @end example -Note: If any argument is inexact, then the result will also be inexact (unless the -procedure can prove that the inaccuracy is not large enough to affect the result, -which is possible only in unusual implementations). If @code{min} or @code{max} is used to compare -numbers of mixed exactness, and the numerical value of the result cannot be -represented as an inexact number without loss of accuracy, then the procedure may -report a violation of an implementation restriction. +Note: If any argument is inexact, then the result will also be inexact +(unless the procedure can prove that the inaccuracy is not large enough to +affect the result, which is possible only in unusual implementations). If +@code{min} or @code{max} is used to compare numbers of mixed exactness, +and the numerical value of the result cannot be represented as an inexact +number without loss of accuracy, then the procedure may report a violation +of an implementation restriction. @end deffn @@ -544,11 +569,11 @@ report a violation of an implementation restriction. These procedures return the sum or product of their arguments. @example -(+ 3 4) @result{} 7 -(+ 3) @result{} 3 -(+) @result{} 0 -(* 4) @result{} 4 -(*) @result{} 1 +(+ 3 4) @result{} 7 +(+ 3) @result{} 3 +(+) @result{} 0 +(* 4) @result{} 4 +(*) @result{} 1 @end example @end deffn @@ -557,20 +582,21 @@ These procedures return the sum or product of their arguments. @deffnx procedure / z @deffnx procedure / z@sub{1} z@sub{2}@dots{} -With two or more arguments, these procedures return the difference or quotient of their -arguments, associating to the left. With one argument, however, they return the additive -or multiplicative inverse of their argument. +With two or more arguments, these procedures return the difference or +quotient of their arguments, associating to the left. With one argument, +however, they return the additive or multiplicative inverse of their +argument. -It is an error if any argument of @code{/} other than the first is an exact zero. If the first -argument is an exact zero, an implementation may return an exact zero unless one of the -other arguments is a NaN. +It is an error if any argument of @code{/} other than the first is an +exact zero. If the first argument is an exact zero, an implementation +may return an exact zero unless one of the other arguments is a NaN. @example -(- 3 4) @result{} -1 -(- 3 4 5) @result{} -6 -(- 3) @result{} -3 -(/ 3 4 5) @result{} 3/20 -(/ 3) @result{} 1/3 +(- 3 4) @result{} -1 +(- 3 4 5) @result{} -6 +(- 3) @result{} -3 +(/ 3 4 5) @result{} 3/20 +(/ 3) @result{} 1/3 @end example @end deffn @@ -580,7 +606,7 @@ other arguments is a NaN. The abs procedure returns the absolute value of its argument. @example -(abs -7) @result{} 7 +(abs -7) @result{} 7 @end example @end deffn @@ -592,13 +618,12 @@ The abs procedure returns the absolute value of its argument. @deffnx procedure truncate-quotient n@sub{1} n@sub{2} @deffnx procedure truncate-remainder n@sub{1} n@sub{2} -These procedures implement -number-theoretic (integer) division. It is an error if @var{n} is zero. -The procedures ending in @code{/} return two integers; the other -procedures return an integer. All the procedures compute a -quotient @var{n@sub{q}} and remainder @var{n@sub{r}} such that -@var{n@sub{1}} = @var{n@sub{2}}@var{n@sub{q}} + @var{n@sub{r}}. For each of the -division operators, there are three procedures defined as follows: +These procedures implement number-theoretic (integer) division. It is +an error if @var{n} is zero. The procedures ending in @code{/} return +two integers; the other procedures return an integer. All the procedures +compute a quotient @var{n@sub{q}} and remainder @var{n@sub{r}} such that +@var{n@sub{1}} = @var{n@sub{2}}@var{n@sub{q}} + @var{n@sub{r}}. For each +of the division operators, there are three procedures defined as follows: @c This is hideous. Can we do any better? @lisp @@ -609,8 +634,8 @@ division operators, there are three procedures defined as follows: The remainder @var{n@sub{r}} is determined by the choice of integer @var{n@sub{q}}: @var{n@sub{r}} = @var{n@sub{1}} @minus{} -@var{n@sub{2}}@var{n@sub{q}}. Each set of -operators uses a different choice of @var{n@sub{q}}: +@var{n@sub{2}}@var{n@sub{q}}. Each set of operators uses a different +choice of @var{n@sub{q}}: @table @code @@ -622,8 +647,8 @@ operators uses a different choice of @var{n@sub{q}}: @end table -For any of the operators, and for integers @var{n@sub{1}} and @var{n@sub{2}} -with @var{n@sub{2}} not equal to 0, +For any of the operators, and for integers @var{n@sub{1}} and +@var{n@sub{2}} with @var{n@sub{2}} not equal to 0, @lisp (= @r{@var{n@sub{1}}} @@ -637,15 +662,15 @@ provided all numbers involved in that computation are exact. Examples: @example -(floor/ 5 2) @result{} 2 1 -(floor/ -5 2) @result{} -3 1 -(floor/ 5 -2) @result{} -3 -1 -(floor/ -5 -2) @result{} 2 -1 -(truncate/ 5 2) @result{} 2 1 -(truncate/ -5 2) @result{} -2 -1 -(truncate/ 5 -2) @result{} -2 1 -(truncate/ -5 -2) @result{} 2 -1 -(truncate/ -5.0 -2) @result{} 2.0 -1.0 +(floor/ 5 2) @result{} 2 1 +(floor/ -5 2) @result{} -3 1 +(floor/ 5 -2) @result{} -3 -1 +(floor/ -5 -2) @result{} 2 -1 +(truncate/ 5 2) @result{} 2 1 +(truncate/ -5 2) @result{} -2 -1 +(truncate/ 5 -2) @result{} -2 1 +(truncate/ -5 -2) @result{} 2 -1 +(truncate/ -5.0 -2) @result{} 2.0 -1.0 @end example @end deffn @@ -655,26 +680,26 @@ Examples: @deffnx procedure modulo n@sub{1} n@sub{2} The @code{quotient} and @code{remainder} procedures are equivalent to -@code{truncate-quotient} and @code{truncate-remainder}, respectively, and -@code{modulo} is equivalent to @code{floor-remainder}. +@code{truncate-quotient} and @code{truncate-remainder}, respectively, +and @code{modulo} is equivalent to @code{floor-remainder}. -Note: These procedures are provided for backward compatibility with earlier -versions of this report. +Note: These procedures are provided for backward compatibility with +earlier versions of this report. @end deffn @deffn procedure gcd n@sub{1}@dots{} @deffnx procedure lcm n@sub{1}@dots{} -These procedures return the greatest common divisor or least common multiple of their -arguments. The result is always non-negative. +These procedures return the greatest common divisor or least common +multiple of their arguments. The result is always non-negative. @example -(gcd 32 -36) @result{} 4 -(gcd) @result{} 0 -(lcm 32 -36) @result{} 288 -(lcm 32.0 -36) @result{} 288.0 ; inexact -(lcm) @result{} 1 +(gcd 32 -36) @result{} 4 +(gcd) @result{} 0 +(lcm 32 -36) @result{} 288 +(lcm 32.0 -36) @result{} 288.0 ; inexact +(lcm) @result{} 1 @end example @end deffn @@ -682,15 +707,16 @@ arguments. The result is always non-negative. @deffn procedure numerator q @deffnx procedure denominator q -These procedures return the numerator or denominator of their argument; the result is -computed as if the argument was represented as a fraction in lowest terms. The -denominator is always positive. The denominator of 0 is defined to be 1. +These procedures return the numerator or denominator of their argument; +the result is computed as if the argument was represented as a fraction +in lowest terms. The denominator is always positive. The denominator of +0 is defined to be 1. @example -(numerator (/ 6 4)) @result{} 3 -(denominator (/ 6 4)) @result{} 2 +(numerator (/ 6 4)) @result{} 3 +(denominator (/ 6 4)) @result{} 2 (denominator - (inexact (/ 6 4))) @result{} 2.0 + (inexact (/ 6 4))) @result{} 2.0 @end example @end deffn @@ -700,34 +726,36 @@ denominator is always positive. The denominator of 0 is defined to be 1. @deffnx procedure truncate x @deffnx procedure round x -These procedures return integers. -The @code{floor} procedure returns the largest integer not larger than @var{x}. -The @code{ceiling} procedure returns the smallest integer not smaller than @var{x}, -@code{truncate} returns the integer closest to @var{x} whose absolute -value is not larger than the absolute value of @var{x}, and @code{round} returns the -closest integer to @var{x}, rounding to even when @var{x} is halfway between two -integers. +These procedures return integers. The @code{floor} procedure returns the +largest integer not larger than @var{x}. The @code{ceiling} procedure +returns the smallest integer not smaller than @var{x}, @code{truncate} +returns the integer closest to @var{x} whose absolute value is not larger +than the absolute value of @var{x}, and @code{round} returns the closest +integer to @var{x}, rounding to even when @var{x} is halfway between +two integers. -Rationale: The @code{round} procedure rounds to even for consistency with the default -rounding mode specified by the IEEE 754 IEEE floating-point standard. +Rationale: The @code{round} procedure rounds to even for consistency with +the default rounding mode specified by the IEEE 754 IEEE floating-point +standard. -Note: If the argument to one of these procedures is inexact, then the result will also -be inexact. If an exact value is needed, the result can be passed to the @code{exact} -procedure. If the argument is infinite or a NaN, then it is returned. +Note: If the argument to one of these procedures is inexact, then the +result will also be inexact. If an exact value is needed, the result can +be passed to the @code{exact} procedure. If the argument is infinite or +a NaN, then it is returned. @example -(floor -4.3) @result{} -5.0 -(ceiling -4.3) @result{} -4.0 -(truncate -4.3) @result{} -4.0 -(round -4.3) @result{} -4.0 - -(floor 3.5) @result{} 3.0 -(ceiling 3.5) @result{} 4.0 -(truncate 3.5) @result{} 3.0 -(round 3.5) @result{} 4.0 ; inexact - -(round 7/2) @result{} 4 ; exact -(round 7) @result{} 7 +(floor -4.3) @result{} -5.0 +(ceiling -4.3) @result{} -4.0 +(truncate -4.3) @result{} -4.0 +(round -4.3) @result{} -4.0 + +(floor 3.5) @result{} 3.0 +(ceiling 3.5) @result{} 4.0 +(truncate 3.5) @result{} 3.0 +(round 3.5) @result{} 4.0 ; inexact + +(round 7/2) @result{} 4 ; exact +(round 7) @result{} 7 @end example @end deffn @@ -735,21 +763,20 @@ procedure. If the argument is infinite or a NaN, then it is returned. @deffn procedure rationalize x y @c TODO: Math mode is probably overkill here. Use normal insertions? -The @code{rationalize} procedure returns the @emph{simplest} rational number -differing from @var{x} by no more than @var{y}. A rational number @var{r@sub{1}} is -@emph{simpler} than another rational number -@var{r@sub{2}} if @math{r_1 = p_1/q_1} and @math{r_2 = p_2/q_2} (in lowest terms) and -@math{|p_1| \leq |p_2|} and @math{|q_1| \leq |q_2|}. Thus 3/5 is simpler than 4/7. -Although not all rationals are comparable in this ordering (consider 2/7 -and 3/5), any interval contains a rational number that is simpler than -every other rational number in that interval (the simpler 2/5 lies -between 2/7 and 3/5). Note that 0 = 0/1 is the simplest rational of -all. +The @code{rationalize} procedure returns the @emph{simplest} rational +number differing from @var{x} by no more than @var{y}. A rational +number @var{r@sub{1}} is @emph{simpler} than another rational number +@var{r@sub{2}} if @math{r_1 = p_1/q_1} and @math{r_2 = p_2/q_2} (in +lowest terms) and @math{|p_1| \leq |p_2|} and @math{|q_1| \leq |q_2|}. +Thus 3/5 is simpler than 4/7. Although not all rationals are comparable +in this ordering (consider 2/7 and 3/5), any interval contains a +rational number that is simpler than every other rational number in +that interval (the simpler 2/5 lies between 2/7 and 3/5). Note that 0 = +0/1 is the simplest rational of all. @example -(rationalize - (exact .3) 1/10) @result{} 1/3 ; exact -(rationalize .3 1/10) @result{} #i1/3 ; inexact +(rationalize (exact .3) 1/10) @result{} 1/3 ; exact +(rationalize .3 1/10) @result{} #i1/3 ; inexact @end example @end deffn @@ -765,26 +792,25 @@ all. @deffnx {inexact library procedure} atan z @deffnx {inexact library procedure} atan y x -These procedures -compute the usual transcendental functions. The @code{log} procedure -computes the natural logarithm of @var{z} (not the base ten logarithm) -if a single argument is given, or the base-@var{z@sub{2}} logarithm of @var{z@sub{1}} -if two arguments are given. -The @code{asin}, @code{acos}, and @code{atan} procedures compute arcsine (sin@sup{@minus{}1}), -arc-cosine (cos@sup{@minus{}1}), and arctangent (tan@sup{@minus{}1}), respectively. -The two-argument variant of @code{atan} computes @code{(angle -(make-rectangular @var{x} @var{y}))} (see below), even in implementations -that don't support complex numbers. +These procedures compute the usual transcendental functions. The +@code{log} procedure computes the natural logarithm of @var{z} (not the +base ten logarithm) if a single argument is given, or the +base-@var{z@sub{2}} logarithm of @var{z@sub{1}} if two arguments are +given. The @code{asin}, @code{acos}, and @code{atan} procedures compute +arcsine (sin@sup{@minus{}1}), arc-cosine (cos@sup{@minus{}1}), and +arctangent (tan@sup{@minus{}1}), respectively. The two-argument variant +of @code{atan} computes @code{(angle (make-rectangular @var{x} +@var{y}))} (see below), even in implementations that don't support +complex numbers. In general, the mathematical functions log, arcsine, arc-cosine, and -arctangent are multiply defined. -The value of log @var{z} is defined to be the one whose imaginary part -lies in the range from @minus{}@greekpi (inclusive if @code{-0.0} is distinguished, -exclusive otherwise) to @greekpi (inclusive). -The value of log 0 is mathematically undefined. +arctangent are multiply defined. The value of log @var{z} is defined to +be the one whose imaginary part lies in the range from @minus{}@greekpi +(inclusive if @code{-0.0} is distinguished, exclusive otherwise) to +@greekpi (inclusive). The value of log 0 is mathematically undefined. With log defined this way, the values of sin@sup{@minus{}1} @var{z}, -cos@sup{@minus{}1} @var{z}, -and tan@sup{@minus{}1} @var{z} are according to the following formul@ae{}: +cos@sup{@minus{}1} @var{z}, and tan@sup{@minus{}1} @var{z} are +according to the following formul@ae{}: @displaymath \sin^{-1} z = -i \log (i z + \sqrt{1 - z^2}) @@ -799,8 +825,8 @@ and tan@sup{@minus{}1} @var{z} are according to the following formul@ae{}: @end displaymath However, @code{(log 0.0)} returns @code{-inf.0} (and @code{(log -0.0)} -returns @code{-inf.0+@greekpi{}i}) if the implementation -supports infinities (and @code{-0.0}). +returns @code{-inf.0+@greekpi{}i}) if the implementation supports +infinities (and @code{-0.0}). The range of @code{(atan }@var{y} @var{x}@code{)} is as in the following table. The asterisk (*) indicates that the entry applies to @@ -838,27 +864,29 @@ implementations that distinguish minus zero. @minus{}@greekpi/2 @end multitable -The above specification follows [34], which in turn cites [26]; refer to these sources for -more detailed discussion of branch cuts, boundary conditions, and implementation of -these functions. When it is possible, these procedures produce a real result from a real -argument. +The above specification follows [34], which in turn cites [26]; refer +to these sources for more detailed discussion of branch cuts, boundary +conditions, and implementation of these functions. When it is possible, +these procedures produce a real result from a real argument. @end deffn @deffn procedure square z -Returns the square of z. This is equivalent to @code{(* }@var{z} @var{z}@code{)}. +Returns the square of z. This is equivalent to +@code{(* }@var{z} @var{z}@code{)}. @example -(square 42) @result{} 1764 -(square 2.0) @result{} 4.0 +(square 42) @result{} 1764 +(square 2.0) @result{} 4.0 @end example @end deffn @deffn {inexact library procedure} sqrt z -Returns the principal square root of @var{z}. The result will have either a positive real part, or a zero real part and a non-negative +Returns the principal square root of @var{z}. The result will have +either a positive real part, or a zero real part and a non-negative imaginary part. @example @@ -913,7 +941,7 @@ Then all of @example (make-rectangular @r{@var{x@sub{1}} @var{x@sub{2}}}) @result{} z -(make-polar @r{@var{x@sub{3}} @var{x@sub{4}}}) @result{} z +(make-polar @r{@var{x@sub{3}} @var{x@sub{4}}}) @result{} z (real-part z) @result{} @r{@var{x@sub{1}}} (imag-part z) @result{} @r{@var{x@sub{2}}} (magnitude z) @result{} |@r{@var{x@sub{3}}}| @@ -924,15 +952,15 @@ are true, where @minus{}@greekpi{} @leq{} @var{x@sub{angle}} @leq{} @greekpi{} with @var{x@sub{angle}} = @var{x@sub{4}} + 2@greekpi{}@var{n} for some integer @var{n}. -The @code{make-polar} procedure may return an inexact complex number even if its -arguments are exact. -The @code{real-part} and @code{imag-part} procedures may return exact real -numbers when applied to an inexact complex number if the corresponding -argument passed to @code{make-rectangular} was exact. +The @code{make-polar} procedure may return an inexact complex +number even if its arguments are exact. The @code{real-part} and +@code{imag-part} procedures may return exact real numbers when applied +to an inexact complex number if the corresponding argument passed to +@code{make-rectangular} was exact. -The @code{magnitude} procedure is the same as @code{abs} for a real argument, -but @code{abs} is in the base library, whereas -@code{magnitude} is in the optional complex library. +The @code{magnitude} procedure is the same as @code{abs} for a real +argument, but @code{abs} is in the base library, whereas @code{magnitude} +is in the optional complex library. @end deffn @@ -940,36 +968,33 @@ but @code{abs} is in the base library, whereas @deffnx procedure exact z The procedure @code{inexact} returns an inexact representation of @var{z}. -The value returned is the -inexact number that is numerically closest to the argument. -For inexact arguments, the result is the same as the argument. For exact -complex numbers, the result is a complex number whose real and imaginary -parts are the result of applying @code{inexact} to the real -and imaginary parts of the argument, respectively. -If an exact argument has no reasonably close inexact equivalent -(in the sense of @code{=}), -then a violation of an implementation restriction may be reported. - -The procedure @code{exact} returns an exact representation of -@var{z}. The value returned is the exact number that is numerically -closest to the argument. -For exact arguments, the result is the same as the argument. For inexact -non-integral real arguments, the implementation may return a rational -approximation, or may report an implementation violation. For inexact -complex arguments, the result is a complex number whose real and -imaginary parts are the result of applying @code{exact} to the -real and imaginary parts of the argument, respectively. -If an inexact argument has no reasonably close exact equivalent, -(in the sense of @code{=}), -then a violation of an implementation restriction may be reported. +The value returned is the inexact number that is numerically closest +to the argument. For inexact arguments, the result is the same as the +argument. For exact complex numbers, the result is a complex number +whose real and imaginary parts are the result of applying @code{inexact} +to the real and imaginary parts of the argument, respectively. If an +exact argument has no reasonably close inexact equivalent (in the sense +of @code{=}), then a violation of an implementation restriction may +be reported. + +The procedure @code{exact} returns an exact representation of @var{z}. The +value returned is the exact number that is numerically closest to +the argument. For exact arguments, the result is the same as the +argument. For inexact non-integral real arguments, the implementation +may return a rational approximation, or may report an implementation +violation. For inexact complex arguments, the result is a complex number +whose real and imaginary parts are the result of applying @code{exact} +to the real and imaginary parts of the argument, respectively. If an +inexact argument has no reasonably close exact equivalent, (in the +sense of @code{=}), then a violation of an implementation restriction +may be reported. These procedures implement the natural one-to-one correspondence between -exact and inexact integers throughout an -implementation-dependent range. @xref{Implementation restrictions}. +exact and inexact integers throughout an implementation-dependent +range. @xref{Implementation restrictions}. -Note: -These procedures were known in @rfivers{} as @code{exact->inexact} and -@code{inexact->exact}, respectively, but they have always accepted +Note: These procedures were known in @rfivers{} as @code{exact->inexact} +and @code{inexact->exact}, respectively, but they have always accepted arguments of any exactness. The new names are clearer and shorter, as well as being compatible with @rsixrs{}. @@ -984,8 +1009,9 @@ as well as being compatible with @rsixrs{}. It is an error if @var{radix} is not one of 2, 8, 10, or 16. -The procedure @code{number->string} takes a number and a radix and returns as a string an -external representation of the given number in the given radix such that +The procedure @code{number->string} takes a number and a radix and +returns as a string an external representation of the given number in +the given radix such that @example (let ((number number) @@ -996,72 +1022,65 @@ external representation of the given number in the given radix such that radix))) @end example -is true. It is an error if no possible result makes this expression true. If omitted, -@var{radix} defaults to 10. +is true. It is an error if no possible result makes this expression +true. If omitted, @var{radix} defaults to 10. -If -@var{z} is inexact, the radix is 10, and the above expression can be satisfied by a result that -contains a decimal point, then the result contains a decimal point and is expressed using -the minimum number of digits (exclusive of exponent and trailing zeroes) needed to -make the above expression true [4, 5]; otherwise the format of the result is unspecified. +If @var{z} is inexact, the radix is 10, and the above expression can be +satisfied by a result that contains a decimal point, then the result +contains a decimal point and is expressed using the minimum number +of digits (exclusive of exponent and trailing zeroes) needed to make +the above expression true [4, 5]; otherwise the format of the result +is unspecified. -The result returned by @code{number->string} never contains an explicit radix prefix. +The result returned by @code{number->string} never contains an explicit +radix prefix. -Note: The error case can occur only when -@var{z} is not a complex number or is a complex number with a non-rational real or -imaginary part. +Note: The error case can occur only when @var{z} is not a complex number +or is a complex number with a non-rational real or imaginary part. -Rationale: If -@var{z} is an inexact number and the radix is 10, then the above expression is normally -satisfied by a result containing a decimal point. The unspecified case allows for -infinities, NaNs, and unusual representations. +Rationale: If @var{z} is an inexact number and the radix is 10, then +the above expression is normally satisfied by a result containing a +decimal point. The unspecified case allows for infinities, NaNs, and +unusual representations. @end deffn @deffn procedure string->number string @deffnx procedure string->number string radix -Returns a number of the maximally precise representation expressed by the given -@var{string}. -It is an error if -@var{radix} is not 2, 8, 10, or 16. +Returns a number of the maximally precise representation expressed by the +given @var{string}. It is an error if @var{radix} is not 2, 8, 10, or 16. -If supplied, -@var{radix} is a default radix that will be overridden if an explicit radix prefix is present in -string (e.g.@: @code{"#o177"}). If +If supplied, @var{radix} is a default radix that will be overridden if an +explicit radix prefix is present in string (e.g.@: @code{"#o177"}). If @var{radix} is not supplied, then the default radix is 10. If -@var{string} is not a syntactically valid notation for a number, or would result in a number that -the implementation cannot represent, then @code{string->number} returns @code{#f}. An error is never -signaled due to the content of -@var{string}. +@var{string} is not a syntactically valid notation for a number, or +would result in a number that the implementation cannot represent, then +@code{string->number} returns @code{#f}. An error is never signaled due +to the content of @var{string}. @example -(string->number "100") @result{} 100 -(string->number "100" 16) @result{} 256 -(string->number "1e2") @result{} 100.0 +(string->number "100") @result{} 100 +(string->number "100" 16) @result{} 256 +(string->number "1e2") @result{} 100.0 @end example -Note: -The domain of @code{string->number} may be restricted by implementations -in the following ways. -If all numbers supported by an implementation are real, then -@code{string->number} is permitted to return @code{#f} whenever -@var{string} uses the polar or rectangular notations for complex -numbers. If all numbers are integers, then -@code{string->number} may return @code{#f} whenever -the fractional notation is used. If all numbers are exact, then -@code{string->number} may return @code{#f} whenever -an exponent marker or explicit exactness prefix is used. -If all inexact -numbers are integers, then -@code{string->number} may return @code{#f} whenever -a decimal point is used. - -The rules used by a particular implementation for @code{string->number} must -also be applied to @code{read} and to the routine that reads programs, in -order to maintain consistency between internal numeric processing, I/O, -and the processing of programs. -As a consequence, the @rfivers{} permission to return @code{#f} when -@var{string} has an explicit radix prefix has been withdrawn. +Note: The domain of @code{string->number} may be restricted by +implementations in the following ways. If all numbers supported by an +implementation are real, then @code{string->number} is permitted to +return @code{#f} whenever @var{string} uses the polar or rectangular +notations for complex numbers. If all numbers are integers, then +@code{string->number} may return @code{#f} whenever the fractional +notation is used. If all numbers are exact, then @code{string->number} may +return @code{#f} whenever an exponent marker or explicit exactness prefix +is used. If all inexact numbers are integers, then @code{string->number} +may return @code{#f} whenever a decimal point is used. + +The rules used by a particular implementation for @code{string->number} +must also be applied to @code{read} and to the routine that reads +programs, in order to maintain consistency between internal numeric +processing, I/O, and the processing of programs. As a consequence, +the @rfivers{} permission to return @code{#f} when @var{string} has an +explicit radix prefix has been withdrawn. @end deffn