Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-advanced-reader.ss" "lang")((modname |33.1|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 (define-struct inex (mantissa sign exponent))
6 ;An inexact number (inex) is a structure
7 ;(make-inex m s e)
8 ;where m, e are N in the interval [0,99] and s is either +1 or -1.
9 ;
10 ;create-inex : N N N -> inex
11 ;Creates an inex from mantissa, sign, and exponent.
13 (define (create-inex mantissa sign exponent)
14 (cond
15 [(and (<= 0 mantissa 99)
16 (<= 0 exponent 99)
17 (= (abs sign) 1)) (make-inex mantissa sign exponent)]
18 [else (error 'create-inex "(<= 0 m 99), +1 or -1, (<= 0 e 99) expected")]))
20 ;inex->number : inex -> number
21 ;Given an-inex, convert it to an exact number.
23 (define (inex->number an-inex)
24 (* (inex-mantissa an-inex)
25 (expt 10 (* (inex-sign an-inex) (inex-exponent an-inex)))))
27 (inex->number (create-inex 55 -1 3))