Bug 20456

Summary: System.Numerics : BigInteger construction from byte array
Product: [Mono] Class Libraries Reporter: Eirik Tsarpalis <eirik>
Component: GeneralAssignee: Rodrigo Kumpera <kumpera>
Status: RESOLVED FIXED    
Severity: normal CC: masafa, mono-bugs+mono, saurabhd
Priority: ---    
Version: 3.4.0   
Target Milestone: Untriaged   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:

Description Eirik Tsarpalis 2014-06-07 13:15:42 UTC
Consider the following F# snippet:

open System.Numerics
let n1 = new BigInteger(-4294967295L)
let n2 = new System.Numerics.BigInteger(n1.ToByteArray())

n1 = n1 // should be true, evaluates to false
Comment 1 Marek Safar 2014-07-04 12:01:08 UTC
C# test

using System;
using System.Numerics;

class X
{
	public static void Main ()
	{
		var n1 = new BigInteger (-4294967295L);
		var n2 = new BigInteger (n1.ToByteArray ());

		var b = n1 == n2; // should be true, evaluates to false
		return;
	}

}

Looks like byte[] ctor is making wrong adjustments and creates internal array with length + 1
Comment 2 Rodrigo Kumpera 2014-07-08 20:05:29 UTC
Fixed in master.
Comment 3 Saurabh 2014-08-05 09:49:09 UTC
I have checked this Issue with following builds and observed that above code mentioned in bug evaluate value to True. This is the screencast for the same: http://www.screencast.com/t/Sf7MrdarwPT3

=== Xamarin Studio ===

Version 5.3 (build 412)
Installation UUID: 2591d519-875d-4afe-a3d9-5fcf391bbd2d
Runtime:
	Mono 3.8.0 ((no/9ffca33)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000002

=== Xamarin.Android ===

Version: 4.16.0 (Business Edition)
Android SDK: /Users/nischal/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: /usr
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

=== Apple Developer Tools ===

Xcode 4.6.3 (2068)
Build 4H1503

=== Xamarin.iOS ===

Version: 7.2.6.28 (Business Edition)
Hash: 606f31a
Branch: 
Build date: 2014-08-01 15:27:48-0400

=== Xamarin.Mac ===

Version: 1.10.0.4 (Business Edition)

=== Build Information ===

Release ID: 503000412
Git revision: 77e042831804079a649ee83092ed36c7c10773a2
Build date: 2014-08-01 06:32:22-04
Xamarin addins: 57e379e6a9454a1c0d97aa3f770e7ae7cc16c522

=== Operating System ===

Mac OS X 10.7.4
Darwin nischals-Mac-mini.local 11.4.0 Darwin Kernel Version 11.4.0
    Mon Apr  9 19:32:15 PDT 2012
    root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64