BigInteger Constructor (Single)

Silverlight

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)

Syntax

```public BigInteger(
float value
)
```

Parameters

value
Type: System.Single
A single-precision floating-point value.

Exceptions

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.

Remarks

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.

Examples

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);

outputBlock.Text += negativeSingle.ToString("N0") + "\n";
outputBlock.Text += negativeNumber.ToString() + "\n";

negativeSingle++;
negativeNumber++;

outputBlock.Text += negativeSingle.ToString("N0") + "\n";
outputBlock.Text += negativeNumber.ToString() + "\n";
// The example displays the following output:
//       -340,282,300,000,000,000,000,000,000,000,000,000,000
//       -340282346638528859811704183484516925440
//       -340,282,300,000,000,000,000,000,000,000,000,000,000
//       -340282346638528859811704183484516925439

```

Version Information

Silverlight

Supported in: 5, 4

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.