35 writes to _bits
System.Runtime.Numerics (35)
System\Numerics\BigInteger.cs (35)
77
_bits
= null;
89
_bits
= null;
94
_bits
= [value];
105
_bits
= null;
127
_bits
= [(nuint)x];
131
_bits
= x <= uint.MaxValue ? [((uint)x)] : [(uint)x, (uint)(x >> BitsPerUInt32)];
144
_bits
= null;
151
_bits
= [(nuint)value];
155
_bits
= value <= uint.MaxValue ? [((uint)value)] : [(uint)value, (uint)(value >> BitsPerUInt32)];
174
_bits
= null;
231
_bits
= new nuint[cu + 1];
241
_bits
= new nuint[cu + 2];
281
_bits
= null;
289
_bits
= new nuint[nuintSize];
302
_bits
= new nuint[size];
320
_bits
= null;
371
_bits
= null;
395
_bits
= null;
399
_bits
= [(uint)_sign];
491
_bits
= null;
500
_bits
= val.AsSpan(0, len).ToArray();
505
_bits
= val;
511
_bits
= val;
530
_bits
= bits;
561
_bits
= null;
571
_bits
= value.ToArray();
641
_bits
= null;
648
_bits
= trimLen == 1 ? [magnitude] : value[..trimLen].ToArray();
654
_bits
= [magnitude];
661
_bits
= [value[0]];
666
_bits
= null;
686
_bits
= value.ToArray();
706
_bits
= null;
710
_bits
= new nuint[bits32.Length];
716
_bits
= new nuint[nuintLen];
373 references to _bits
System.Runtime.Numerics (373)
System\Number.BigInteger.cs (3)
833
if (value.
_bits
== null)
871
int base1E9BufferLength = (int)(value.
_bits
.Length * digitRatio) + 1;
875
BigIntegerToBase1E9(value.
_bits
, base1E9Buffer, out int written);
System\Numerics\BigInteger.cs (370)
46
/// <see cref="_sign"/> and <see cref="
_bits
"/> is <see langword="null"/>.
47
/// For all other values, <see cref="_sign"/> is +1 or -1 and the magnitude is in <see cref="
_bits
"/>.
232
_bits
[cu] = (nuint)(man >> cbit);
235
_bits
[cu - 1] = (nuint)(man << (64 - cbit));
242
_bits
[cu + 1] = (uint)(man >> (cbit + BitsPerUInt32));
243
_bits
[cu] = (uint)(man >> cbit);
246
_bits
[cu - 1] = (nuint)(uint)man << (BitsPerUInt32 - cbit);
290
_bits
[0] = (uint)bits[0];
293
_bits
[0] |= (nuint)(uint)bits[1] << 32;
296
_bits
[1] = (uint)bits[2];
303
_bits
[0] = (uint)bits[0];
306
_bits
[1] = (uint)bits[1];
309
_bits
[2] = (uint)bits[2];
317
if (
_bits
.Length is 1 &&
_bits
[0] <= int.MaxValue)
319
_sign = _sign < 0 ? -(int)
_bits
[0] : (int)
_bits
[0];
694
/// Reads <see cref="
_bits
"/> as <see cref="uint"/>[] for backward compatibility with previous
711
Buffer.BlockCopy(bits32, 0,
_bits
, 0, bits32.Length * sizeof(uint));
721
_bits
[i / 2] = (nuint)(lo | (hi << 32));
730
/// Serializes <see cref="
_bits
"/> as <see cref="uint"/>[] for backward compatibility with previous
739
if (
_bits
is not null)
743
bits32 = new uint[
_bits
.Length];
744
Buffer.BlockCopy(
_bits
, 0, bits32, 0,
_bits
.Length * sizeof(uint));
748
int len =
_bits
.Length * 2;
749
if ((uint)(
_bits
[^1] >> 32) == 0)
755
for (int i = 0; i <
_bits
.Length; i++)
757
bits32[i * 2] = (uint)
_bits
[i];
760
bits32[i * 2 + 1] = (uint)(
_bits
[i] >> 32);
779
if (
_bits
is null)
789
int iu =
_bits
.Length - 1;
790
return BitOperations.IsPow2(
_bits
[iu]) && !
_bits
.AsSpan(0, iu).ContainsAnyExcept(0u);
796
public bool IsOne => _sign == 1 &&
_bits
is null;
798
public bool IsEven =>
_bits
is null ? (_sign & 1) == 0 : (
_bits
[0] & 1) == 0;
888
return new BigInteger((int)NumericsHelpers.Abs(value._sign), value.
_bits
);
918
bool trivialDividend = dividend.
_bits
is null;
919
bool trivialDivisor = divisor.
_bits
is null;
937
Debug.Assert(dividend.
_bits
is not null);
941
int size = dividend.
_bits
.Length;
946
BigIntegerCalculator.Divide(dividend.
_bits
, NumericsHelpers.Abs(divisor._sign), quotient, out nuint rest);
952
Debug.Assert(divisor.
_bits
is not null);
961
int commonOffset = dividend.
_bits
[0] == 0 && divisor.
_bits
[0] == 0
962
? BigIntegerCalculator.GetCommonLimbOffset(dividend.
_bits
, divisor.
_bits
)
964
ReadOnlySpan<nuint> dividendBits = dividend.
_bits
.AsSpan(commonOffset);
965
ReadOnlySpan<nuint> divisorBits = divisor.
_bits
.AsSpan(commonOffset);
974
int size = dividend.
_bits
.Length;
1027
if (value.
_bits
is null)
1039
h = value.
_bits
[^1];
1040
m = value.
_bits
.Length > 1 ? value.
_bits
[^2] : 0;
1043
b = (long)value.
_bits
.Length * 64 - c;
1050
h = (uint)value.
_bits
[^1];
1051
m = value.
_bits
.Length > 1 ? (uint)value.
_bits
[^2] : 0;
1052
l = value.
_bits
.Length > 2 ? (uint)value.
_bits
[^3] : 0;
1056
b = (long)value.
_bits
.Length * 32 - c;
1094
bool trivialLeft = left.
_bits
is null;
1095
bool trivialRight = right.
_bits
is null;
1104
Debug.Assert(right.
_bits
is not null);
1106
? BigIntegerCalculator.Gcd(right.
_bits
, NumericsHelpers.Abs(left._sign))
1107
: new BigInteger(+1, right.
_bits
);
1112
Debug.Assert(left.
_bits
is not null);
1114
? BigIntegerCalculator.Gcd(left.
_bits
, NumericsHelpers.Abs(right._sign))
1115
: new BigInteger(+1, left.
_bits
);
1118
Debug.Assert(left.
_bits
is not null && right.
_bits
is not null);
1119
return GreatestCommonDivisor(left.
_bits
, right.
_bits
);
1192
if (value.
_bits
is null)
1205
ReadOnlySpan<nuint> bits = value.
_bits
;
1253
Debug.Assert(dividend.
_bits
is not null);
1260
ReadOnlySpan<nuint> dividendBits = dividend.
_bits
;
1334
bool trivialValue = value.
_bits
is null;
1335
bool trivialExponent = exponent.
_bits
is null;
1336
bool trivialModulus = modulus.
_bits
is null;
1343
trivialValue ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), exponent.
_bits
!, NumericsHelpers.Abs(modulus._sign)) :
1344
trivialExponent ? BigIntegerCalculator.Pow(value.
_bits
!, NumericsHelpers.Abs(exponent._sign), NumericsHelpers.Abs(modulus._sign)) :
1345
BigIntegerCalculator.Pow(value.
_bits
!, exponent.
_bits
!, NumericsHelpers.Abs(modulus._sign));
1351
int size = (modulus.
_bits
?.Length ?? 1) << 1;
1357
BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), NumericsHelpers.Abs(exponent._sign), modulus.
_bits
!, bits);
1361
BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), exponent.
_bits
!, modulus.
_bits
!, bits);
1366
BigIntegerCalculator.Pow(value.
_bits
!, NumericsHelpers.Abs(exponent._sign), modulus.
_bits
!, bits);
1370
BigIntegerCalculator.Pow(value.
_bits
!, exponent.
_bits
!, modulus.
_bits
!, bits);
1406
bool trivialValue = value.
_bits
is null;
1665
int size = BigIntegerCalculator.PowBound(power, value.
_bits
!.Length);
1668
BigIntegerCalculator.Pow(value.
_bits
, power, bits);
1678
if (
_bits
is null)
1684
hash.AddBytes(MemoryMarshal.AsBytes(
_bits
.AsSpan()));
1696
if (
_bits
is null)
1703
if ((_sign ^ other) < 0 || (cu =
_bits
.Length) > maxLimbs)
1712
return
_bits
[0] == uu;
1717
? (uint)
_bits
[0] == uu
1718
: ((ulong)(uint)
_bits
[1] << 32 | (uint)
_bits
[0]) == uu;
1730
if (
_bits
is null)
1735
int cu =
_bits
.Length;
1744
return
_bits
[0] == other;
1749
? (uint)
_bits
[0] == other
1750
: ((ulong)(uint)
_bits
[1] << 32 | (uint)
_bits
[0]) == other;
1756
return _sign == other._sign &&
_bits
.AsSpan().SequenceEqual(other.
_bits
);
1761
if (
_bits
is null)
1768
if ((_sign ^ other) < 0 || (cu =
_bits
.Length) > maxLimbs)
1778
uuTmp =
_bits
[0];
1783
? ((ulong)(uint)
_bits
[1] << 32 | (uint)
_bits
[0])
1784
: (uint)
_bits
[0];
1798
if (
_bits
is null)
1803
int cu =
_bits
.Length;
1814
uuTmp =
_bits
[0];
1819
? ((ulong)(uint)
_bits
[1] << 32 | (uint)
_bits
[0])
1820
: (uint)
_bits
[0];
1835
if (
_bits
is null)
1838
other.
_bits
is not null ? -other._sign :
1844
if (other.
_bits
is null)
1849
int bitsResult = BigIntegerCalculator.Compare(
_bits
, other.
_bits
);
2013
nuint[]? bits =
_bits
;
2189
Debug.Assert(
_bits
is null || _sign == 0 ? buffer.Length == 2 : buffer.Length >=
_bits
.Length + 1);
2193
if (
_bits
is null)
2200
_bits
.CopyTo(buffer);
2201
buffer = buffer.Slice(0,
_bits
.Length + 1);
2264
if ((
_bits
is null) || (
_bits
.Length <= 4))
2279
highBits =
_bits
[^1];
2280
lowBitsCount =
_bits
.Length - 1;
2284
highBits = ((ulong)
_bits
[^1] << BitsPerUInt32) + (uint)
_bits
[^2];
2285
lowBitsCount =
_bits
.Length - 2;
2400
if (left.
_bits
is null && right.
_bits
is null)
2406
? Add(left.
_bits
, left._sign, right.
_bits
, -right._sign)
2407
: Subtract(left.
_bits
, left._sign, right.
_bits
, right._sign);
2548
if (value.
_bits
is null)
2559
nuint[]? bits = value.
_bits
;
2592
nuint[]? bits = value.
_bits
;
2726
nuint[]? bits = value.
_bits
;
2745
nuint[]? bits = value.
_bits
;
2768
if (value.
_bits
is null)
2773
if (value.
_bits
.Length > 1)
2781
return checked((int)value.
_bits
[0]);
2784
if (value.
_bits
[0] > UInt32HighBit)
2790
return -(int)value.
_bits
[0];
2795
if (value.
_bits
is null)
2800
int len = value.
_bits
.Length;
2811
uu = value.
_bits
[0];
2816
? ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2817
: (uint)value.
_bits
[0];
2835
if (value.
_bits
is null)
2840
int len = value.
_bits
.Length;
2852
uu = len > 1 ? new UInt128(value.
_bits
[1], value.
_bits
[0]) : (UInt128)(ulong)value.
_bits
[0];
2857
((ulong)((len > 3) ? (uint)value.
_bits
[3] : 0) << 32 | (uint)value.
_bits
[2]),
2858
((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2864
? (UInt128)((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2865
: (UInt128)(uint)value.
_bits
[0];
2890
nuint[]? bits = value.
_bits
;
2920
if (value.
_bits
is null)
2926
return value.
_bits
.Length <= 1 && value._sign >= 0
2927
? checked((uint)value.
_bits
[0])
2935
if (value.
_bits
is null)
2940
int len = value.
_bits
.Length;
2949
return value.
_bits
[0];
2953
? ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2954
: (uint)value.
_bits
[0];
2963
if (value.
_bits
is null)
2968
int len = value.
_bits
.Length;
2979
? new UInt128(value.
_bits
[1], value.
_bits
[0])
2980
: (UInt128)(ulong)value.
_bits
[0];
2985
((ulong)((len > 3) ? (uint)value.
_bits
[3] : 0) << 32 | (uint)value.
_bits
[2]),
2986
((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2991
return ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0]);
2994
return (uint)value.
_bits
[0];
3198
left.
_bits
is null && right.
_bits
is null ? (BigInteger)(left._sign & right._sign) :
3213
return left.
_bits
is null && right.
_bits
is null
3219
left.
_bits
is null && right.
_bits
is null
3229
int xLen = left.
_bits
?.Length ?? 1;
3230
int yLen = right.
_bits
?.Length ?? 1;
3248
int xLen = left.
_bits
?.Length ?? 1;
3249
int yLen = right.
_bits
?.Length ?? 1;
3258
int xLen = left.
_bits
?.Length ?? 1;
3259
int yLen = right.
_bits
?.Length ?? 1;
3269
left.
_bits
, left._sign,
3270
right.
_bits
, right._sign,
3299
if (value.
_bits
is null)
3305
ReadOnlySpan<nuint> bits = value.
_bits
;
3413
if (value.
_bits
is null)
3426
ReadOnlySpan<nuint> bits = value.
_bits
;
3466
if (value.
_bits
is null)
3476
int size = value.
_bits
.Length + 1;
3479
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
3486
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
3488
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
3496
public static BigInteger operator -(BigInteger value) => new BigInteger(-value._sign, value.
_bits
);
3502
if (value.
_bits
is null)
3511
int size = value.
_bits
.Length + 1;
3514
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
3520
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
3522
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
3532
if (value.
_bits
is null)
3541
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
3543
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
3549
int size = value.
_bits
.Length + 1;
3552
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
3562
if (left.
_bits
is null && right.
_bits
is null)
3568
? Subtract(left.
_bits
, left._sign, right.
_bits
, -right._sign)
3569
: Add(left.
_bits
, left._sign, right.
_bits
, right._sign);
3574
if (left.
_bits
is null && right.
_bits
is null)
3591
return Multiply(left.
_bits
, left._sign, right.
_bits
, right._sign);
3651
bool trivialDividend = dividend.
_bits
is null;
3652
bool trivialDivisor = divisor.
_bits
is null;
3668
Debug.Assert(dividend.
_bits
is not null);
3670
int size = dividend.
_bits
.Length;
3674
BigIntegerCalculator.Divide(dividend.
_bits
, NumericsHelpers.Abs(divisor._sign), quotient);
3683
Debug.Assert(dividend.
_bits
is not null && divisor.
_bits
is not null);
3690
int commonOffset = dividend.
_bits
[0] == 0 && divisor.
_bits
[0] == 0
3691
? BigIntegerCalculator.GetCommonLimbOffset(dividend.
_bits
, divisor.
_bits
)
3693
ReadOnlySpan<nuint> dividendBits = dividend.
_bits
.AsSpan(commonOffset);
3694
ReadOnlySpan<nuint> divisorBits = divisor.
_bits
.AsSpan(commonOffset);
3723
bool trivialDividend = dividend.
_bits
is null;
3724
bool trivialDivisor = divisor.
_bits
is null;
3740
Debug.Assert(dividend.
_bits
is not null);
3741
nuint remainder = BigIntegerCalculator.Remainder(dividend.
_bits
, NumericsHelpers.Abs(divisor._sign));
3745
Debug.Assert(dividend.
_bits
is not null && divisor.
_bits
is not null);
3752
int commonOffset = dividend.
_bits
[0] == 0 && divisor.
_bits
[0] == 0
3753
? BigIntegerCalculator.GetCommonLimbOffset(dividend.
_bits
, divisor.
_bits
)
3755
ReadOnlySpan<nuint> dividendBits = dividend.
_bits
.AsSpan(commonOffset);
3756
ReadOnlySpan<nuint> divisorBits = divisor.
_bits
.AsSpan(commonOffset);
3763
int size = dividend.
_bits
.Length;
3867
nuint[]? bits =
_bits
;
3903
if (
_bits
is not null)
3908
Debug.Assert(
_bits
.Length > 0);
3910
Debug.Assert(
_bits
.Length > 1 ||
_bits
[0] > int.MaxValue);
3912
Debug.Assert(
_bits
[^1] != 0);
3914
Debug.Assert(
_bits
.Length <= MaxLength);
3945
if (value.
_bits
is null)
3974
if (value.
_bits
is null)
3990
return BitOperations.LeadingZeroCount(value.
_bits
[^1]) & 31;
3996
if (value.
_bits
is null)
4007
for (int i = 0; i < value.
_bits
.Length; i++)
4009
nuint part = value.
_bits
[i];
4018
int firstNonZero = value.
_bits
.AsSpan().IndexOfAnyExcept((nuint)0);
4024
part = ~value.
_bits
[i] + 1;
4028
while (i < value.
_bits
.Length)
4031
part = ~value.
_bits
[i];
4039
if (Environment.Is64BitProcess && (uint)(value.
_bits
[^1] >> BitsPerUInt32) == 0)
4058
if (value.
_bits
is null)
4066
return Rotate(value.
_bits
, neg, rotateAmount);
4079
if (value.
_bits
is null)
4087
return Rotate(value.
_bits
, neg, -(long)rotateAmount);
4354
if (value.
_bits
is null)
4362
nuint part = value.
_bits
[0];
4365
for (int i = 1; (part == 0) && (i < value.
_bits
.Length); i++)
4367
part = value.
_bits
[i];
4392
nuint[]? bits =
_bits
;
4432
nuint[]? bits =
_bits
;
4510
nuint[]? bits =
_bits
;
4585
nuint[]? bits =
_bits
;
4636
return value.
_bits
is null
4638
: (BigInteger)(((long)value.
_bits
.Length * BigIntegerCalculator.BitsPerLimb - 1) ^ BitOperations.LeadingZeroCount(value.
_bits
[^1]));
4683
if (value.
_bits
is null)
4690
if (sign.
_bits
is null)
4707
return value.
_bits
is null
4785
return value.
_bits
is null
4787
: (value.
_bits
[0] & 1) == 0;
4820
return value.
_bits
is null
4822
: (value.
_bits
[0] & 1) != 0;
5371
if (value.
_bits
is not null)
5388
if (value.
_bits
is not null)
5430
if (value.
_bits
is not null)
5447
if (value.
_bits
is not null)
5491
if (value.
_bits
is not null)
5514
if (value.
_bits
is not null)
5570
if (value.
_bits
is not null)
5572
nuint bits = value.
_bits
[0];
5593
if (value.
_bits
is not null)
5595
nuint bits = value.
_bits
[0];
5641
if (value.
_bits
is not null)
5643
actualResult = IsNegative(value) ? (short)(~value.
_bits
[0] + 1) : (short)value.
_bits
[0];
5657
if (value.
_bits
is not null)
5659
actualResult = IsNegative(value) ? (int)(~value.
_bits
[0] + 1) : (int)value.
_bits
[0];
5673
if (value.
_bits
is not null)
5679
bits = value.
_bits
[0];
5685
if (value.
_bits
.Length >= 2)
5687
bits = value.
_bits
[1];
5691
bits |= value.
_bits
[0];
5713
if (value.
_bits
is not null)
5720
lowerBits = value.
_bits
[0];
5722
if (value.
_bits
.Length >= 2)
5724
upperBits = value.
_bits
[1];
5729
if (value.
_bits
.Length >= 4)
5731
upperBits = value.
_bits
[3];
5735
if (value.
_bits
.Length >= 3)
5737
upperBits |= value.
_bits
[2];
5740
if (value.
_bits
.Length >= 2)
5742
lowerBits = value.
_bits
[1];
5746
lowerBits |= value.
_bits
[0];
5770
if (value.
_bits
is not null)
5772
nuint bits = value.
_bits
[0];
5799
if (value.
_bits
is not null)
5801
actualResult = IsNegative(value) ? (sbyte)(~value.
_bits
[0] + 1) : (sbyte)value.
_bits
[0];
5821
if (value.
_bits
is not null)
5823
nuint bits = value.
_bits
[0];
5844
if (value.
_bits
is not null)
5846
uint bits = (uint)value.
_bits
[0];
5867
if (value.
_bits
is not null)
5873
bits = value.
_bits
[0];
5879
if (value.
_bits
.Length >= 2)
5881
bits = value.
_bits
[1];
5885
bits |= value.
_bits
[0];
5907
if (value.
_bits
is not null)
5914
lowerBits = value.
_bits
[0];
5916
if (value.
_bits
.Length >= 2)
5918
upperBits = value.
_bits
[1];
5923
if (value.
_bits
.Length >= 4)
5925
upperBits = value.
_bits
[3];
5929
if (value.
_bits
.Length >= 3)
5931
upperBits |= value.
_bits
[2];
5934
if (value.
_bits
.Length >= 2)
5936
lowerBits = value.
_bits
[1];
5940
lowerBits |= value.
_bits
[0];
5964
if (value.
_bits
is not null)
5966
nuint bits = value.
_bits
[0];
6021
if (value.
_bits
is null)
6033
ReadOnlySpan<nuint> bits = value.
_bits
;