Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Scheme (programming language)
(section)
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.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)