# Re: Project #2

Stephen Edwards (edwards@CS.VT.EDU)
Wed, 3 Oct 2001 09:25:41 -0400

```Message-ID:  <3BBB11D5.3DD7DF46@cs.vt.edu>
Date:         Wed, 3 Oct 2001 09:25:41 -0400
From: Stephen Edwards <edwards@CS.VT.EDU>
Subject:      Re: Project #2
```

> My question is as follows...
> how do we handle multiple divisors?

The same as everything else--you'll need to
keep track of intermediate results as a rational number,
and perform the operation as a rational operation.

> 1/2/3... (or iconst 1 iconst 2 iconst 3 idiv idiv)
> should the output be 3/2
> or should it be 1/.666?

Note that 1/2/3 is not the same as
(iconst 1 iconst 2 iconst 3 idiv idiv ireturn).

1/2/3 == (iconst 1 iconst 2 idiv iconst 3 idiv ireturn).

So, for these two examples, here is the proper output:

(iconst 1 iconst 2 idiv iconst 3 idiv ireturn) produces:

1/6 = .16666666666666666

(iconst 1 iconst 2 iconst 3 idiv idiv ireturn) produces:

3/2 = 1.5

In all such cases, the rational representation printed out by your
program shall consist of a single numerator followed by a slash followed
by a single denominator, and this rational number must be in reduced form.
As another example:

(iconst 100 iconst 22 idiv ireturn) produces:

50/11 = 4.545454545454546

I strongly urge everyone to read Section 4 of the Scheme reference
manual (Numbers) in detail. Play around with some simple numeric
expressions and write statements in the scheme interpreter, and you
should find that producing output in the form specified above is
extremely easy (if you think it is hard and requires a lot of programming,
then you are doing it wrong).

-- Steve

```--
Stephen Edwards            604 McBryde Hall          Dept. of Computer Science
e-mail      : edwards@cs.vt.edu           U.S. mail: Virginia Tech (VPI&SU)
office phone: (540)-231-5723                         Blacksburg, VA  24061-0106
-------------------------------------------------------------------------------
```