From: Tao Stein <taostein@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] strange integer division result in ocamlopt ...
Date: Sun, 19 Apr 2015 01:14:48 +0200 [thread overview]
Message-ID: <CABs4TjKGAp=qUriLwsk_x=oLCb4owd-xrn5DVro5JducFzokUA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1092 bytes --]
I'm getting a strange result using ocamlopt that seems to violate the basic
axioms of integer division.
Some context first:
taostein@~/b2/f2: which ocamlopt
/Users/taostein/.opam/4.02.1/bin/ocamlopt
taostein@~/b2/f2: ocamlopt -o foo.opt foo.ml
taostein@~/b2/f2: which ocamlc
/Users/taostein/.opam/4.02.1/bin/ocamlc
taostein@~/artcode/b2/f2: ocamlc -o foo foo.ml
Built with ocamlopt, the following code throws an exception. Built with
ocamlc it does not.
let k1 = 1;;
let rec f i k =
if (((i / k1) * k1 + (i mod k1)) <> i)
then (raise (Failure "violation of integer division axiom"))
else (if (i < 10) then (f (i + 1) k) else ()) in
f 0 1;;
Now, if I change the above only on line 3 changing k1 to k, then it works
fine, no problem.
let k1 = 1;;
let rec f i k =
if (((i / k) * k + (i mod k)) <> i)
then (raise (Failure "violation of integer division axiom"))
else (if (i < 10) then (f (i + 1) k) else ()) in
f 0 1;;
No exception in either ocamlc or ocamlopt.
Using ocamlopt, it seems 1 mod 1 = 1. This is problematic.
Tao Stein / 石涛
[-- Attachment #2: Type: text/html, Size: 1514 bytes --]
next reply other threads:[~2015-04-18 23:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-18 23:14 Tao Stein [this message]
2015-04-18 23:20 ` hugo
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='CABs4TjKGAp=qUriLwsk_x=oLCb4owd-xrn5DVro5JducFzokUA@mail.gmail.com' \
--to=taostein@gmail.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