comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Language Revision : "/" and "div"
Date: Sat, 1 May 2010 11:25:36 +0200
Date: 2010-05-01T11:25:36+02:00	[thread overview]
Message-ID: <1wcpicfucvich$.1ec1rjytiuj5s$.dlg@40tude.net> (raw)
In-Reply-To: 8aa58be8-a9b2-4653-8234-e5b6a70f310f@k41g2000yqb.googlegroups.com

On Fri, 30 Apr 2010 23:52:18 -0700 (PDT), vincent.diemunsch@gmail.com
wrote:

> I wonder why Ada uses "/" to express the integer division and not
> "div".

Because in most languages / denotes "integer division", which mathematical
integer lack (:-)).

> This leads to the fact that an expression like 4/3*6 that any decent calculator
> would evaluate as 8 is in Ada evaluated as 6 !!! That is a shame :-).

1. The calculator uses reals, not integers.
2. There exist expression which cannot be evaluated (as decimal fractions
of finite length), e.g. 1.0/3.0
3. There exist operations not closed in R. So a "decent" calculator should
return j for sqrt(-1.0) 
4. There exist operations not closed in C, e.g. multi-valued functions. A
"decent" calculator must return a set of values?

> - discard the function "/" (left, right : Integer) return Integer and
> replace it by the operator "div",

AFAIK, ARG does not introduce backward incompatibilities unless absolutely
necessary (in their opinion (:-)). I doubt that / could fall under this
category.

> that sounds quite logical with the existing "rem" and "mod".
> - add a fraction package with a function "/" (left, right :
> Integer'base) return Fraction; as constructor.

Arguably better would be "div" as a full division, e.g. returning a tuple
of the result and the remainder. In both cases there is a problem that the
result type (be it fraction, tuple, rational etc) shall be defined
(inferred) for each integer type including user-defined ones. Ada lacks any
mechanics for this.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2010-05-01  9:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-01  6:52 Language Revision : "/" and "div" vincent.diemunsch
2010-05-01  9:25 ` Dmitry A. Kazakov [this message]
2010-05-01 10:46 ` Georg Bauhaus
2010-05-01 16:26 ` Jeffrey R. Carter
2010-05-02 21:33 ` Gene
2010-05-05  2:31 ` Yannick Duchêne (Hibou57)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox