Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Hendrik Boom <hendrik@topoi.pooq.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] truncated division, remainder and arithmetics
Date: Wed, 27 Jan 2016 05:02:54 -0500	[thread overview]
Message-ID: <20160127100254.GB2762@topoi.pooq.com> (raw)
In-Reply-To: <1453854887.31205.2.camel@gmail.com>

On Wed, Jan 27, 2016 at 01:34:47AM +0100, peio wrote:
> Good evening,
> 
> 
> while doing some modular arithmetic I discovered that OCaml uses the
> 'truncated division' convention for the `/` (quotient) operator.
> Actually this convention may seem innocent but it greatly affects the
> `mod` (remainder) operator: the sign of the result is the same as
> dividend.
> 
> After some research I realized that lots of people (D.Knuth!)
> criticized this convention in favor of floored division (sign of
> remainder same as divisor) or euclidean division (remainder always
> positive). I know such a key component of the language isn't likely to
> be changed but I would like to get some of the rationals behind this
> decision.

In the old days when all machines hadn't settled down to one true 
binary arithmetic convention, I noticed that the machines where the 
remainder had the same sign as the dividend were two's complement 
machines, and the ones where the remainder had the same sign as the 
divisor were one's complement machines.

-- hendrik


  parent reply	other threads:[~2016-01-27 14:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-27  0:34 peio
2016-01-27  9:56 ` François Bobot
2016-01-27 10:02 ` Hendrik Boom [this message]
2016-01-27 10:18 ` Xavier Leroy
2016-01-28 19:03   ` peio

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=20160127100254.GB2762@topoi.pooq.com \
    --to=hendrik@topoi.pooq.com \
    --cc=caml-list@inria.fr \
    /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