From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id A85F17F6D8 for ; Sun, 18 Jan 2015 20:30:04 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.218.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.218.52 as permitted sender) identity=mailfrom; client-ip=209.85.218.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-oi0-f52.google.com) identity=helo; client-ip=209.85.218.52; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-oi0-f52.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuYAAG8JvFTRVdo0lWdsb2JhbABbg1hcgwKzYo1qgWmFcQKBBwdDAQEBAQERAQEBAQcNCQkSMIQNAQEEEhEdARsSCwEDDAYFBAcaHQICIgERAQUBChIGEwgKEId1AQMRDa5SPjGLLoFrgneJWwoZJwMKVINIAQEBAQEFAQEBAQEBAQEUAQUOj2cEB4JogUEFhD4GjVyFUIFKjxYSI4EMCYIjHYFRPTEBgkIBAQE X-IPAS-Result: AuYAAG8JvFTRVdo0lWdsb2JhbABbg1hcgwKzYo1qgWmFcQKBBwdDAQEBAQERAQEBAQcNCQkSMIQNAQEEEhEdARsSCwEDDAYFBAcaHQICIgERAQUBChIGEwgKEId1AQMRDa5SPjGLLoFrgneJWwoZJwMKVINIAQEBAQEFAQEBAQEBAQEUAQUOj2cEB4JogUEFhD4GjVyFUIFKjxYSI4EMCYIjHYFRPTEBgkIBAQE X-IronPort-AV: E=Sophos;i="5.09,422,1418079600"; d="scan'208";a="117520665" Received: from mail-oi0-f52.google.com ([209.85.218.52]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 18 Jan 2015 20:29:35 +0100 Received: by mail-oi0-f52.google.com with SMTP id h136so2574595oig.11 for ; Sun, 18 Jan 2015 11:29:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=3wpT3B+Nj/D0k3omtdczoYKQ862UkJiJpz7YijtcyYM=; b=BGijcldPlYSUjB+YSCsK6WpdNMOL/G83Ei0TClPudSTNhsAp3RByALoj2cjmF9kGFN f3KBLcHlVNqg10A6zUNpAmjB7M6tr4x3uTn0LAzcjWfn0FflaRq+BeI9OZOGtId8WbkT UgSboR1qdNSjwDFbONdrzuWukeG8hUH1I5PvFAxvz1lErW23+5N4gPDwLDj/HSsBP4Jx qc/P1501sNKQOB18MkyCzCMwhE5OhSBgfXMBYljMMEUm+1c2qc1sSKyQxQBvjd0NKfE3 XUejtmSB289tesPxqZrqlxaTjOCYCLYTQPzu2stamv0kb1cgEx11wx5u3QdB9JBsmJBf uUIQ== X-Received: by 10.202.52.131 with SMTP id b125mr15220845oia.93.1421609374171; Sun, 18 Jan 2015 11:29:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.76.39 with HTTP; Sun, 18 Jan 2015 11:28:54 -0800 (PST) In-Reply-To: <54BBFFF7.6030106@mehnert.org> References: <54BBFFF7.6030106@mehnert.org> From: Gabriel Scherer Date: Sun, 18 Jan 2015 20:28:54 +0100 Message-ID: To: Hannes Mehnert Cc: caml-list Content-Type: multipart/alternative; boundary=001a113d3f68c1d0d6050cf2393e Subject: Re: [Caml-list] behaviour of mod --001a113d3f68c1d0d6050cf2393e Content-Type: text/plain; charset=UTF-8 This is at least documented in the manual ( http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html ): > Note that x mod y is negative only if x < 0. I suppose the idea was to make the least surprising choice (assuming people knew , and also have the behavior coincide with mod_float. (Interestingly, the IEEE754 norm requires a "remainder" operation that has an even stranger behavior (modulo is defined from the round-to-nearest division) and I haven't proposed anywhere.) On Sun, Jan 18, 2015 at 7:48 PM, Hannes Mehnert wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA384 > > Hi, > > is the behaviour of modulo arithmetics intentional: > -5 mod 4 = -1 ? > > While this reflects the C behaviour, my expectation was to always have > a positive result: > -5 mod 4 = 3 > > Any hints? > > hannes > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2 > > iQIcBAEBCQAGBQJUu//3AAoJELyJZYjffCjuQH0QAL7FTKcguf2mKMVm1wu+jYvv > b5yOBl+X0vMBCNWjpMfYVf1nIfo+z5cNF+1zy1kHaozE2BV10qywzWe+mzq+1VMo > g1knplZbxahdTgf1Ix+BqF+Fk0voFfUTW/l9Zrg07B5wUEOFcFXKNo14eWSatTs0 > tVtSAk6fTffz7IPU/QJfvi7euQ5q6e5MVyvoorpjIz2j/OJ0QXw+catlSPXWdyeW > /2TmdeX6WZuiSruEBAvDgDi8Qcp9x/q1abAjdnrZgfmY3+MxNrFZ+7M+QD+mUua6 > pgOe2xdb2gRr5/pOqMLxGpfWZ8b695TS31jZj0GJOZ4sgX/Az/eq1wHSyXiGDpWP > dTr/GUPJWNUEWNeqrF88sOPJK4Zjqr19v7NX86wxvwfQGM4qCbEuYvkVQwBOhtgn > /ewgArQNVHyeAH7R8Ze0S5nqVGDRyJwDj3ef4EVvLGLuibs/fI72x4SQ2x2Xfoz7 > tgkkb0g1So15iVo1z3FDbTbeJBaZh/0lyqBno7w4FmJkoc4Ool9DarKaBe+SqHqP > ErYMK+bA9P7e+rBqySnB92dsClg17v2lmzGuKd4damcaAJvsscOJXWbLvteQbxo5 > eL8TG2sHCdOV5H4dJCpudUzVkA5dYnJUZuSVG/JAyyZWYm/kkQX0obJJo49GMH4h > MvZ9C+veJNgwRY540fqj > =s3KW > -----END PGP SIGNATURE----- > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --001a113d3f68c1d0d6050cf2393e Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
This is at least documented in the manual ( http= ://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html ):
=C2= =A0 > Note that x mod y = is negative only if x < 0.

I suppos= e the idea was to make the least surprising choice (assuming people knew , = and also have the behavior coincide with mod_float. (Interestingly, the IEE= E754 norm requires a "remainder" operation that has an even stran= ger behavior (modulo is defined from the round-to-nearest division) and I h= aven't proposed anywhere.)

On Sun, Jan 18, 2015 at 7:48 PM, Hannes Mehnert <h= annes@mehnert.org> wrote:
-= ----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA384

Hi,

is the behaviour of modulo arithmetics intentional:
=C2=A0-5 mod 4 =3D -1 ?

While this reflects the C behaviour, my expectation was to always have
a positive result:
=C2=A0-5 mod 4 =3D 3

Any hints?

hannes
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCQAGBQJUu//3AAoJELyJZYjffCjuQH0QAL7FTKcguf2mKMVm1wu+jYvv
b5yOBl+X0vMBCNWjpMfYVf1nIfo+z5cNF+1zy1kHaozE2BV10qywzWe+mzq+1VMo
g1knplZbxahdTgf1Ix+BqF+Fk0voFfUTW/l9Zrg07B5wUEOFcFXKNo14eWSatTs0
tVtSAk6fTffz7IPU/QJfvi7euQ5q6e5MVyvoorpjIz2j/OJ0QXw+catlSPXWdyeW
/2TmdeX6WZuiSruEBAvDgDi8Qcp9x/q1abAjdnrZgfmY3+MxNrFZ+7M+QD+mUua6
pgOe2xdb2gRr5/pOqMLxGpfWZ8b695TS31jZj0GJOZ4sgX/Az/eq1wHSyXiGDpWP
dTr/GUPJWNUEWNeqrF88sOPJK4Zjqr19v7NX86wxvwfQGM4qCbEuYvkVQwBOhtgn
/ewgArQNVHyeAH7R8Ze0S5nqVGDRyJwDj3ef4EVvLGLuibs/fI72x4SQ2x2Xfoz7
tgkkb0g1So15iVo1z3FDbTbeJBaZh/0lyqBno7w4FmJkoc4Ool9DarKaBe+SqHqP
ErYMK+bA9P7e+rBqySnB92dsClg17v2lmzGuKd4damcaAJvsscOJXWbLvteQbxo5
eL8TG2sHCdOV5H4dJCpudUzVkA5dYnJUZuSVG/JAyyZWYm/kkQX0obJJo49GMH4h
MvZ9C+veJNgwRY540fqj
=3Ds3KW
-----END PGP SIGNATURE-----

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--001a113d3f68c1d0d6050cf2393e--