Fundamentals of CS I (CS151 2001S) : Reference

real?: determine whether a value is real

Predicatereal?
Parametersn, a number
PurposeDetermines if v is a real number (no complex part).
ProducesA truth value: true (#t) if n is a real number, false (#f) if it's not a real number.
PreconditionsOnly one parameter (verified).
PostconditionsReturns true if and only if the parameter is a real number. Note that my version of Scheme seems to treat any non-complex numbers as real. Note also that values that are not numbers (e.g., lists and symbols) are not real.
Examples
> (real? 1)
#t
> (real? 3/2)
#t
> (real? -1/2)
#t
> (real? 1.3)
#t
> (real? (sqrt 2))
#t
> (exp 1)
2.718281828459045
> (real? (exp 1))
#t
> (real? (sqrt -1))
#f
> (real? 'a)
#f

Disclaimer: I usually create these pages on the fly. This means that they are rarely proofread and may contain bad grammar and incorrect details. It also means that I may update them regularly (see the history for more details). Feel free to contact me with any suggestions for changes.

This page was generated by Siteweaver on Thu Feb 22 05:48:17 2001.
This page may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2001S/real-p.html.
You may validate this page's HTML.
The source was last modified Wed Jan 31 22:41:39 2001.