You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 6010 Reporter:@glondu Assigned to:@xavierleroy Status: closed (set by @xavierleroy on 2015-12-11T18:18:51Z) Resolution: fixed Priority: normal Severity: major Version: 4.00.1 Category: otherlibs
Bug description
This bug has been originally reported in Debian by Drake Wilson at:
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 =
let s offset count = string_of_big_int (extract_big_int mu offset count);;
val s : int -> int -> string =
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 information
Same behaviour with OCaml version 4.00.1.
The text was updated successfully, but these errors were encountered:
Original bug ID: 6010
Reporter: @glondu
Assigned to: @xavierleroy
Status: closed (set by @xavierleroy on 2015-12-11T18:18:51Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 4.00.1
Category: otherlibs
Bug description
This 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 =
let s offset count = string_of_big_int (extract_big_int mu offset count);;
val s : int -> int -> string =
s 0 16;;
s 16 16;;
s 32 16;;
s 48 16;;
(* Okay so far... *)
s 64 16;;
(* Oops! *)
s 56 16;;
(* Function seems to think this is a 2^64-1. *)
eq_big_int (big_int_of_int 255) (extract_big_int mu 56 16);;
(* It's not just a problem with the stringifier. *)
eq_big_int (big_int_of_int (-1)) mu;;
(* Nor is it a problem with the earlier negation. *)
Additional information
Same behaviour with OCaml version 4.00.1.
The text was updated successfully, but these errors were encountered: