------- Start of forwarded message -------
まつもと ゆきひろです

comp.lang.pythonからこのような話題が流れてきました。
識者の意見が聞きたいです。

要するに5/2が2.5であるべきかって話ですが。

Date: Mon, 30 Jul 2001 05:58:22 +0900
Posted: Sun, 29 Jul 2001 13:58:15 -0700
From: Paul Prescod <paulp / ActiveState.com>
Subject: [ruby-talk:18759] Re: Ruby as opposed to Python?
To: ruby-talk / ruby-lang.org (ruby-talk ML)

Yukihiro Matsumoto wrote:
> 
>...
> 
> Ah, you mean you believe 5/2 should be 2.5, do you?
> 
> I don't believe it.  Any operation on two exact numbers should not
> result in inexact number, unless explicitly specified.  So 5/2 may
> return 5/2 (rational number) in the future, but not 2.5.

Python may adopt rationals one day also, but the change to having 5/2
return a rational will be much less painful if the code out there
expects it to return a float than if the code expects it to return the
floor. Most code doesn't break when you make it more accurate but
switching from floor division to integer division breaks a lot of code
in an obvious way. The sooner it is done the sooner he can move on to
tackling rationals.

Anyhow, even if Python or Ruby never adopts rationals, I tend to think
that the substitutability principle is more important than the principle
that "any operation on two exact numbers should not result in inexact
number, unless explicitly specified." I would say if you strongly
believe that then the consistent thing to do is disallow all uses of
exact integers in place of floats. You could just as easily extend the
principle to say: "no operation involving an exact number should result
in an inexact number." Then people would be trained that floats and
integers are deeply different and distinct and they wouldn't accidently
pass integers to functions expecting floats.
-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.ActiveState.com/pythoncookbook