Export (0) Print
Expand All

BigInteger Constructor (Single)

Initializes a new instance of the BigInteger structure using a single-precision floating-point value.

Namespace:  System.Numerics
Assembly:  System.Numerics (in System.Numerics.dll)

public BigInteger(
	float value
)

Parameters

value
Type: System.Single

A single-precision floating-point value.

ExceptionCondition
OverflowException

The value of value is Single.NaN.

-or-

The value of value is Single.NegativeInfinity.

-or-

The value of value is Single.PositiveInfinity.

Any fractional part of the value parameter is truncated when instantiating a BigInteger object.

Because of the lack of precision of the Single data type, calling this constructor can result in data loss.

The BigInteger value that results from calling this constructor is identical to the value that results from explicitly assigning a Single value to a BigInteger.

The following example illustrates the use of the BigInteger(Single) constructor to instantiate a BigInteger object. It also illustrates the loss of precision that may occur when you use the Single data type. A Single is assigned a large negative value, which is then assigned to a BigInteger object. As the output shows, this assignment involves a loss of precision. Both values are then incremented by one. The output shows that the BigInteger object reflects the changed value, whereas the Single object does not.

// Create a BigInteger from a large negative Single value 
float negativeSingle = Single.MinValue;
BigInteger negativeNumber = new BigInteger(negativeSingle);

Console.WriteLine(negativeSingle.ToString("N0"));
Console.WriteLine(negativeNumber.ToString("N0"));

negativeSingle++;
negativeNumber++;

Console.WriteLine(negativeSingle.ToString("N0"));
Console.WriteLine(negativeNumber.ToString("N0"));
// The example displays the following output: 
//       -340,282,300,000,000,000,000,000,000,000,000,000,000 
//       -340,282,346,638,528,859,811,704,183,484,516,925,440 
//       -340,282,300,000,000,000,000,000,000,000,000,000,000 
//       -340,282,346,638,528,859,811,704,183,484,516,925,439

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft