Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Scheme (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Numerical tower=== {{Main|Numerical tower}} Scheme specifies a comparatively full set of numerical datatypes including [[complex number|complex]] and [[rational number|rational]] types, which is known in Scheme as the numerical tower (R5RS sec. 6.2<ref name="r5rs"/>). The standard treats these as abstractions, and does not commit the implementor to any particular internal representations. Numbers may have the quality of exactness. An exact number can only be produced by a sequence of exact operations involving other exact numbers—inexactness is thus contagious. The standard specifies that any two implementations must produce equivalent results for all operations resulting in exact numbers. The R5RS standard specifies procedures <code>exact->inexact</code> and <code>inexact->exact</code> which can be used to change the exactness of a number. <code>inexact->exact</code> produces "the exact number that is numerically closest to the argument". <code>exact->inexact</code> produces "the inexact number that is numerically closest to the argument". The R6RS standard omits these procedures from the main report, but specifies them as R5RS compatibility procedures in the standard library (rnrs r5rs (6)). In the R5RS standard, Scheme implementations are not required to implement the whole numerical tower, but they must implement "a coherent subset consistent with both the purposes of the implementation and the spirit of the Scheme language" (R5RS sec. 6.2.3).<ref name="r5rs"/> The new R6RS standard does require implementation of the whole tower, and "exact integer objects and exact rational number objects of practically unlimited size and precision, and to implement certain procedures...so they always return exact results when given exact arguments" (R6RS sec. 3.4, sec. 11.7.1).<ref name="r6rs"/> Example 1: exact arithmetic in an implementation that supports exact rational complex numbers. <syntaxhighlight lang="Scheme"> ;; Sum of three rational real numbers and two rational complex numbers (define x (+ 1/3 1/4 -1/5 -1/3i 405/50+2/3i)) x ===> 509/60+1/3i ;; Check for exactness. (exact? x) ===> #t </syntaxhighlight> Example 2: Same arithmetic in an implementation that supports neither exact rational numbers nor complex numbers but does accept real numbers in rational notation. <syntaxhighlight lang="Scheme"> ;; Sum of four rational real numbers (define xr (+ 1/3 1/4 -1/5 405/50)) ;; Sum of two rational real numbers (define xi (+ -1/3 2/3)) xr ===> 8.48333333333333 xi ===> 0.333333333333333 ;; Check for exactness. (exact? xr) ===> #f (exact? xi) ===> #f </syntaxhighlight> Both implementations conform to the R5RS standard but the second does not conform to R6RS because it does not implement the full numerical tower.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Scheme (programming language)
(section)
Add topic