Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006010OCamlOCaml otherlibspublic2013-05-07 19:542013-05-08 10:44
Reporterglondu 
Assigned Toxleroy 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.00.1 
Target VersionFixed in Version 
Summary0006010: Big_int.extract_big_int does not handle negative numbers properly
DescriptionThis bug has been originally reported in Debian by Drake Wilson at:

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=707127 [^]

Big_int.extract_big_int does not handle negative numbers properly.

This function seems to assume that unrepresented prefix regions of
bits in a Big_int.big_int are always zero, but this is not so for
negative numbers. The documentation explicitly states that a two's
complement representation is used for those, but see the transcript
with comments inline.
Steps To Reproduce% ocaml nums.cma
        Objective Caml version 3.12.1

# open Big_int;;
# let mu = minus_big_int unit_big_int;;
val mu : Big_int.big_int = <abstr>
# let s offset count = string_of_big_int (extract_big_int mu offset count);;
val s : int -> int -> string = <fun>
# s 0 16;;
- : string = "65535"
# s 16 16;;
- : string = "65535"
# s 32 16;;
- : string = "65535"
# s 48 16;;
- : string = "65535"
  (* Okay so far... *)
# s 64 16;;
- : string = "0"
  (* Oops! *)
# s 56 16;;
- : string = "255"
  (* Function seems to think this is a 2^64-1. *)
# eq_big_int (big_int_of_int 255) (extract_big_int mu 56 16);;
- : bool = true
  (* It's not just a problem with the stringifier. *)
# eq_big_int (big_int_of_int (-1)) mu;;
- : bool = true
  (* Nor is it a problem with the earlier negation. *)
Additional InformationSame behaviour with OCaml version 4.00.1.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0009256)
xleroy (administrator)
2013-05-08 10:44

Fixed in trunk, commit 13660.

- Issue History
Date Modified Username Field Change
2013-05-07 19:54 glondu New Issue
2013-05-08 10:44 xleroy Note Added: 0009256
2013-05-08 10:44 xleroy Assigned To => xleroy
2013-05-08 10:44 xleroy Status new => resolved
2013-05-08 10:44 xleroy Resolution open => fixed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker