Bug#707127: ocaml-base: Big_int.extract_big_int does not handle negative numbers properly
Package: ocaml-base
Version: 3.12.1-4
Severity: normal
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:
% 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. *)
---> Drake Wilson
-- System Information:
Debian Release: 7.0
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.2.0-3-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages ocaml-base depends on:
ii libc6 2.13-38
ii libx11-6 2:1.5.0-1
ii ocaml-base-nox [ocaml-base-nox-3.12.1] 3.12.1-4
ii tcl8.5 8.5.11-2
ii tk8.5 8.5.11-2
ocaml-base recommends no packages.
ocaml-base suggests no packages.
-- no debconf information
Reply to: