# Class 06: Numeric Values

Back to Symbols and Lists. On to Characters and Strings.

This outline is also available in PDF.

Held: Tuesday, January 30, 2007

Summary: Today we begin our first real exploration of numbers in Scheme.

Related Pages:

Due

Notes:

• Homework 4 is now ready. It is due on Friday.
• For some reason, every semester I forget to write the following: If you want to ask a question on a homework, please put the word question in the subject of the email. If I just get an email like HW3 or Exam 1, I assume that you're submitting it.
• Two readings for Wednesday: Characters in Scheme and Strings in Scheme.

Overview:

• Types.
• Review of Reading: Numbers, Kinds of Numbers, and Numeric Operations.
• Lab.
• Reflection.

## Types

• As you may have noted in your first experiments with Scheme, Scheme assigns types to variables.
• For example, a value might be a list, or a number, or ....
• Computer scientists often think of types in two different ways:
• Data-driven: A type is a set of values.
• Purpose-driven: A type provides information on the valid operations that may be applied to a piece of data.
• We will alternate between the two definitions.
• Many languages (particularly the ones you've reported being familiar with) require you to assign a type to a variable when you declare that variable.
• Scheme does not require you to assign types ot variables; it checks the type of each operand when it executes a procedure.
• Scheme also provides procedures that let you determine the type of a value.
• As the semester progresses, you will learn new types.

## Scheme's Numeric Types

• Instead of a general numbers type, Scheme provides a variety of kinds of numbers.
• Integers are numbers without a fractional component.
• Rational numbers can be expressed as the ratio of two integers.
• Real numbers appear somewhere on the number line.
• In mathematics, real numbers can be rational or irrational.
• In Scheme, real numbers are all rational.
• Complex numbers may include an imaginary component.
• Scheme also represents some numbers exactly and some numbers inexactly.
• It may surprise you to see which numbers are represented inexactly. (We'll return to this issue later.)
• Some important numeric predicates (procedures that return true or false): `number?`, `real?`, `rational?`, `complex?`, `integer?`, `exact?`, and `inexact?`.
• Some important numeric procedures: `numerator`, `denominator`, `quotient`, and `sqrt`.

## Lab

Back to Symbols and Lists. On to Characters and Strings.

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

This document was generated by Siteweaver on Thu Sep 13 20:54:39 2007.
The source to the document was last modified on Thu Jan 18 12:30:12 2007.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2007S/Outlines/outline.06.html`.

You may wish to validate this document's HTML ; ;

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright © 2007 Samuel A. Rebelsky. This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License. To view a copy of this license, visit `http://creativecommons.org/licenses/by-nc/2.5/` or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.