Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006753OCamlotherlibspublic2015-01-19 04:582016-12-07 11:49
Reporterfuruse 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version4.02.1 
Target Version4.02.2+dev / +rc1Fixed in Version4.02.2+dev / +rc1 
Summary0006753: Num.mod_num behaves differently depending on its internal representation
DescriptionBig_int.mod_big_int returns always 0 or positive, as stated in its document, i.e. (-5) mod 3 = 1 in Big_int.

However, in Num, the results are unstable:

mod_num (num_of_big_int (big_int_of_int (-5)) (num_of_big_int (big_int_of_int 3)) returns -2, probably because -5 and 3 are represented as Int (-5) and Int 3.

mod_num (Big_int (big_int_of_int (-5)) (Big_int (big_int_of_int 3)) returns 1.

Well, mod_num saids nothing about its results in details so it is not strictly a bug but this should be filed at least.

TagsNo tags attached.
Attached Files? file icon test_mod_num.ml [^] (1,205 bytes) 2015-02-19 20:03 [Show Content]

- Relationships

-  Notes
(0013140)
furuse (reporter)
2015-01-19 05:05
edited on: 2015-01-19 05:06

(* The following demonstrates the problem *)

open Num
open Big_int

let () = print_endline (string_of_int (-5 mod 3))

let mf = num_of_int (-5)
let t = num_of_int 3
let () = print_endline (string_of_num (mod_num mf t))

let mf = num_of_big_int (big_int_of_int (-5))
let t = num_of_big_int (big_int_of_int 3)
let () = print_endline (string_of_num (mod_num mf t))

let mf = Big_int (big_int_of_int (-5))
let t = Big_int (big_int_of_int 3)
let () = print_endline (string_of_num (mod_num mf t))

(0013316)
doligez (administrator)
2015-02-19 19:09

> Well, mod_num saids nothing about its results in details so it is not strictly a bug but this should be filed at least.

That's not really true: mod_num says it's the remainder of euclidean division, which is a complete formal specification. This bug is definitely a bug.
(0013318)
doligez (administrator)
2015-02-19 20:06
edited on: 2015-03-01 18:02

It's worse than you think: there are 9 cases to test (for `a` and `b` each being one of Int, Big_int, Ratio).
See the attached test file:

When `a` and `b` are both positive, all is well.
When `a` is negative the Int/Int case is wrong.
When `b` is negative, the Ratio/* and */Ratio cases are wrong.

(0013364)
doligez (administrator)
2015-03-01 18:05

For reference:

http://en.wikipedia.org/wiki/Modulo_operation [^]
http://research.microsoft.com/pubs/151917/divmodnote.pdf [^]
(0013827)
xleroy (administrator)
2015-05-06 10:39

Tentative fix in commit 16086 on version/4.02. Damien's nifty test passes. A code review by someone else would be welcome.

- Issue History
Date Modified Username Field Change
2015-01-19 04:58 furuse New Issue
2015-01-19 05:05 furuse Note Added: 0013140
2015-01-19 05:06 furuse Note Edited: 0013140 View Revisions
2015-02-19 19:09 doligez Note Added: 0013316
2015-02-19 20:03 doligez File Added: test_mod_num.ml
2015-02-19 20:06 doligez Note Added: 0013318
2015-02-19 20:06 doligez Status new => confirmed
2015-02-19 20:06 doligez Target Version => 4.02.2+dev / +rc1
2015-03-01 18:02 doligez Note Edited: 0013318 View Revisions
2015-03-01 18:05 doligez Note Added: 0013364
2015-05-06 10:39 xleroy Note Added: 0013827
2015-05-06 10:39 xleroy Status confirmed => resolved
2015-05-06 10:39 xleroy Resolution open => fixed
2015-05-06 10:39 xleroy Fixed in Version => 4.02.2+dev / +rc1
2016-12-07 11:49 xleroy Status resolved => closed
2017-02-23 16:42 doligez Category OCaml otherlibs => otherlibs


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker