Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: Edmund GRIMLEY EVANS <edmundo@rano.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Integer arithmetic: mod
Date: Mon, 19 Nov 2001 16:49:11 +0100	[thread overview]
Message-ID: <20011119164911.B8623@pauillac.inria.fr> (raw)
In-Reply-To: <20011109103008.GA22605@rano.org>; from edmundo@rano.org on Fri, Nov 09, 2001 at 10:30:08AM +0000

> I strongly advise against leaving the meaning of any built-in or
> library function or operator as implementation-defined. If you do this
> you will get unportable programs and inefficient programs (because
> people who want their programs to be portable will be forced to define
> their own versions of the functions).

I can agree with this argument.

> In my opinion and in most people's opinion, as far as I can tell, if
> you're starting afresh, the best way to define integer division is as
> rounding downwards. Integer remainder, to be consistent with this, has
> the sign of the divisor. There are lots of arguments that support this
> type of division, both mathematical and practical, and the only
> arguments against it seem to involve compatibility: the other sort of
> division is faster on some widely used hardware, is required by some
> widely used programming languages and assumed by some existing
> software.

Well, all hardware today implements round-towards-zero for division,
and this is unlikely to change in the future since ISO C9x requires
this behavior, so this will remain the behavior of "/" in OCaml.
We certainly do not want to penalize the existing programs that use
"/" and "mod" correctly, i.e. on positive arguments.

I'm favorable to providing proper Euclidean division and modulus as
library functions.  But: I disagree with your statement that

> the best way to define integer division is as
> rounding downwards. Integer remainder, to be consistent with this, has
> the sign of the divisor.

The way I learned Euclidean division in college is that the quotient q
and the modulus r of a divided by b are defined by

        a = b * q + r  with 0 <= r < |b|

e.g. the modulus is never negative, and division does not necessarily
rounds downwards.  I believe what mathematically-oriented minds really
want is a modulus that is always positive.

Any mathematician on this list who could look it up in Bourbaki?

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2001-11-19 15:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-09 10:30 Edmund GRIMLEY EVANS
2001-11-19 15:49 ` Xavier Leroy [this message]
2001-11-19 16:48   ` Vesa Karvonen
  -- strict thread matches above, loose matches on Subject: below --
2001-11-19 16:39 Krishnaswami, Neel
2001-08-06 13:23 Dave Berry
     [not found] <9khicj$3n3$1@qrnik.zagroda>
2001-08-04 20:25 ` Marcin 'Qrczak' Kowalczyk
2001-08-05  8:05   ` Chris Hecker
2001-08-06  1:06     ` John Gerard Malecki
2001-08-04 10:49 Kai Kaminski
2001-08-04 18:48 ` Chris Hecker
2001-08-05 23:35 ` John Max Skaller
2001-08-10 22:10   ` Kai Kaminski
2001-08-06  9:10 ` Xavier Leroy
2001-08-10 22:29   ` Kai Kaminski
2001-08-13 15:21     ` Xavier Leroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20011119164911.B8623@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=edmundo@rano.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox