Subject: Re: 10 Reasons Why Scheme is Better Than C/C++
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1996/12/04
Newsgroups: comp.lang.scheme,comp.lang.c++,comp.lang.java.programmer
Message-ID: <5837bn$li8@tokyo.engr.sgi.com>

David Hanley  <david@netright.com> wrote:
+---------------
| No, the integer division of 1/3 is 0.  Period.  Claiming this correct
| result as a language defect is foolish.  
+---------------

The language defect is C++'s (and C's before it). As we were all taught
in grade school, 1 divided by 3 is 1/3 (one third). And that's what you
get in Scheme... which includes has rational numbers. The fact that C
didn't know about anything but "int" and "double" is a historical wart that
C++ inherited, but it's *NOT* particularly correct -- quite the contrary.

As someone else pointed out, if you *want* truncation in Scheme, you can
*ask* for it, several ways, in fact:

	(floor (/ 1 3)) ==> 0
	(ceiling (/ 1 3)) ==> 1

or more simply:

	(quotient 1 3) ==> 0

It's simply that in Scheme it's not automatic that division of exact numbers
will truncate. Instead, division of exact numbers gives you an exact result,
namely, an exact rational number:

	(/ 22674322497976 104331282936392) ==> 617/2839

How do you say *that* in C++?


-Rob

-----
Rob Warnock, 7L-551		rpw3@sgi.com
Silicon Graphics, Inc.		http://reality.sgi.com/rpw3/
2011 N. Shoreline Blvd.		Phone: 415-933-1673  FAX: 415-933-0979
Mountain View, CA  94043	PP-ASEL-IA