caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] strange integer division result in ocamlopt ...
@ 2015-04-18 23:14 Tao Stein
  2015-04-18 23:20 ` hugo
  0 siblings, 1 reply; 2+ messages in thread
From: Tao Stein @ 2015-04-18 23:14 UTC (permalink / raw)
  To: caml-list

[-- 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 --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] strange integer division result in ocamlopt ...
  2015-04-18 23:14 [Caml-list] strange integer division result in ocamlopt Tao Stein
@ 2015-04-18 23:20 ` hugo
  0 siblings, 0 replies; 2+ messages in thread
From: hugo @ 2015-04-18 23:20 UTC (permalink / raw)
  To: Tao Stein; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1291 bytes --]

see http://caml.inria.fr/mantis/view.php?id=6749

On Sat, Apr 18, 2015 at 7:14 PM, Tao Stein <taostein@gmail.com> wrote:

>
> 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: 2024 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-04-18 23:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-18 23:14 [Caml-list] strange integer division result in ocamlopt Tao Stein
2015-04-18 23:20 ` hugo

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).