Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #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 12687dd9 2023-08-04 jrmu (define-struct inex (mantissa sign exponent))
5 12687dd9 2023-08-04 jrmu
6 12687dd9 2023-08-04 jrmu ;An inexact number (inex) is a structure
7 12687dd9 2023-08-04 jrmu ;(make-inex m s e)
8 12687dd9 2023-08-04 jrmu ;where m, e are N in the interval [0,99] and s is either +1 or -1.
9 12687dd9 2023-08-04 jrmu ;
10 12687dd9 2023-08-04 jrmu ;create-inex : N N N -> inex
11 12687dd9 2023-08-04 jrmu ;Creates an inex from mantissa, sign, and exponent.
12 12687dd9 2023-08-04 jrmu
13 12687dd9 2023-08-04 jrmu (define (create-inex mantissa sign exponent)
14 12687dd9 2023-08-04 jrmu (cond
15 12687dd9 2023-08-04 jrmu [(and (<= 0 mantissa 99)
16 12687dd9 2023-08-04 jrmu (<= 0 exponent 99)
17 12687dd9 2023-08-04 jrmu (= (abs sign) 1)) (make-inex mantissa sign exponent)]
18 12687dd9 2023-08-04 jrmu [else (error 'create-inex "(<= 0 m 99), +1 or -1, (<= 0 e 99) expected")]))
19 12687dd9 2023-08-04 jrmu
20 12687dd9 2023-08-04 jrmu ;inex->number : inex -> number
21 12687dd9 2023-08-04 jrmu ;Given an-inex, convert it to an exact number.
22 12687dd9 2023-08-04 jrmu
23 12687dd9 2023-08-04 jrmu (define (inex->number an-inex)
24 12687dd9 2023-08-04 jrmu (* (inex-mantissa an-inex)
25 12687dd9 2023-08-04 jrmu (expt 10 (* (inex-sign an-inex) (inex-exponent an-inex)))))
26 12687dd9 2023-08-04 jrmu
27 12687dd9 2023-08-04 jrmu (inex->number (create-inex 55 -1 3))