What is the limit of the Value Type BigInteger in C#?

后端 未结 3 1669
走了就别回头了
走了就别回头了 2021-01-01 22:03

As described in MSDN BigInteger is :

An immutable type that represents an arbitrarily large integer whose value in theory has no upper or lower boun

3条回答
  •  醉话见心
    2021-01-01 22:10

    As a confirmation to the answer from Jon Skeet, I looked to the source code of BigInteger. It actually contains two internal properties as follow:

    internal int _sign;
    internal uint[] _bits;
    

    _bits is used by almost all private/public methods within the class which are used to read/write the actual data.

    _sign is used to keep the sign of the BigInteger.

    The private methods are extensively using binary operators and calculations. Here is a small list of constants used in the class that might reflect a bit the limits:

    private const int knMaskHighBit = -2147483648;
    private const uint kuMaskHighBit = 2147483648U;
    private const int kcbitUint = 32;
    private const int kcbitUlong = 64;
    private const int DecimalScaleFactorMask = 16711680;
    private const int DecimalSignMask = -2147483648;
    

    PS: I should have commented on J.S. answer, but a comment is too short. To view the source code, either download it or decompile System.Numerics.dll.

提交回复
热议问题