# Class 06: Numeric Values

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

This outline is also available in PDF.

Held: Monday, 4 September 2006

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

Related Pages:

Notes:

• Groups for the week assigned. Check the eboard for details.
• There was no Con Brio concert this past weekend. Sorry for the confusion.
• Although some forms of extra credit can be repeated week after week (e.g., attending a football game), I will cap any particular form at two units (one credit).
• More extra credit this week: Tuesday extra (12:45-2:00 p.m. in Science 2424), Convo (11-noon, Thursday, Herrick).

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 Nov 30 21:43:20 2006.
The source to the document was last modified on Mon Sep 4 08:43:32 2006.
This document may be found at `http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2006F/Outlines/outline.06.html`.

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

Samuel A. Rebelsky, rebelsky@grinnell.edu

Copyright © 2006 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.