caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Integer arithmetic: mod
Date: 4 Aug 2001 20:25:35 GMT	[thread overview]
Message-ID: <slrn.pl.9momhv.4c1.qrczak@qrnik.zagroda> (raw)
In-Reply-To: <9khicj$3n3$1@qrnik.zagroda>

Sat, 04 Aug 2001 11:48:07 -0700, Chris Hecker <checker@d6.com> pisze:

> Most computer languages (and chips) simply say "(a/b)*b + a mod b =
> a" and leave it at that.

Fortunately not all, e.g. in Python (-123) % 10 == 7. In C89 the
behavior for negative numbers was left implementation-defined but
in C99 it is specified as truncation towards 0.

> Unfortunately, people (and language and chip designers) assume
> (-4)/3 = -1 (truncate towards zero) rather than -2 (floor),

Not all people: Donald Knuth clearly disagrees. He has written
something along the lines "beware of programming languages which use
a different definition than the one which says (-4)/3 = -2".

Haskell has both: div & mod truncate downwards, quot & rem truncate
towards 0.

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK

-------------------
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-08-05  5:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9khicj$3n3$1@qrnik.zagroda>
2001-08-04 20:25 ` Marcin 'Qrczak' Kowalczyk [this message]
2001-08-05  8:05   ` Chris Hecker
2001-08-06  1:06     ` John Gerard Malecki
2001-11-19 16:39 Krishnaswami, Neel
  -- strict thread matches above, loose matches on Subject: below --
2001-11-09 10:30 Edmund GRIMLEY EVANS
2001-11-19 15:49 ` Xavier Leroy
2001-11-19 16:48   ` Vesa Karvonen
2001-08-06 13:23 Dave Berry
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=slrn.pl.9momhv.4c1.qrczak@qrnik.zagroda \
    --to=qrczak@knm.org.pl \
    --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;
as well as URLs for NNTP newsgroup(s).