35 writes to _bits
System.Runtime.Numerics (35)
System\Numerics\BigInteger.cs (35)
73
_bits
= null;
85
_bits
= null;
90
_bits
= [value];
101
_bits
= null;
123
_bits
= [(nuint)x];
127
_bits
= x <= uint.MaxValue ? [((uint)x)] : [(uint)x, (uint)(x >> BitsPerUInt32)];
140
_bits
= null;
147
_bits
= [(nuint)value];
151
_bits
= value <= uint.MaxValue ? [((uint)value)] : [(uint)value, (uint)(value >> BitsPerUInt32)];
170
_bits
= null;
227
_bits
= new nuint[cu + 1];
237
_bits
= new nuint[cu + 2];
277
_bits
= null;
285
_bits
= new nuint[nuintSize];
298
_bits
= new nuint[size];
316
_bits
= null;
367
_bits
= null;
391
_bits
= null;
395
_bits
= [(uint)_sign];
487
_bits
= null;
496
_bits
= val.AsSpan(0, len).ToArray();
501
_bits
= val;
507
_bits
= val;
526
_bits
= bits;
557
_bits
= null;
567
_bits
= value.ToArray();
637
_bits
= null;
644
_bits
= trimLen == 1 ? [magnitude] : value[..trimLen].ToArray();
650
_bits
= [magnitude];
657
_bits
= [value[0]];
662
_bits
= null;
682
_bits
= value.ToArray();
702
_bits
= null;
706
_bits
= new nuint[bits32.Length];
712
_bits
= new nuint[nuintLen];
367 references to _bits
System.Runtime.Numerics (367)
System\Number.BigInteger.cs (3)
812
if (value.
_bits
== null)
859
int base1E9BufferLength = (int)(value.
_bits
.Length * digitRatio) + 1;
863
BigIntegerToBase1E9(value.
_bits
, base1E9Buffer, out int written);
System\Numerics\BigInteger.cs (364)
42
/// <see cref="_sign"/> and <see cref="
_bits
"/> is <see langword="null"/>.
43
/// For all other values, <see cref="_sign"/> is +1 or -1 and the magnitude is in <see cref="
_bits
"/>.
228
_bits
[cu] = (nuint)(man >> cbit);
231
_bits
[cu - 1] = (nuint)(man << (64 - cbit));
238
_bits
[cu + 1] = (uint)(man >> (cbit + BitsPerUInt32));
239
_bits
[cu] = (uint)(man >> cbit);
242
_bits
[cu - 1] = (nuint)(uint)man << (BitsPerUInt32 - cbit);
286
_bits
[0] = (uint)bits[0];
289
_bits
[0] |= (nuint)(uint)bits[1] << 32;
292
_bits
[1] = (uint)bits[2];
299
_bits
[0] = (uint)bits[0];
302
_bits
[1] = (uint)bits[1];
305
_bits
[2] = (uint)bits[2];
313
if (
_bits
.Length is 1 &&
_bits
[0] <= int.MaxValue)
315
_sign = _sign < 0 ? -(int)
_bits
[0] : (int)
_bits
[0];
690
/// Reads <see cref="
_bits
"/> as <see cref="uint"/>[] for backward compatibility with previous
707
Buffer.BlockCopy(bits32, 0,
_bits
, 0, bits32.Length * sizeof(uint));
717
_bits
[i / 2] = (nuint)(lo | (hi << 32));
726
/// Serializes <see cref="
_bits
"/> as <see cref="uint"/>[] for backward compatibility with previous
735
if (
_bits
is not null)
739
bits32 = new uint[
_bits
.Length];
740
Buffer.BlockCopy(
_bits
, 0, bits32, 0,
_bits
.Length * sizeof(uint));
744
int len =
_bits
.Length * 2;
745
if ((uint)(
_bits
[^1] >> 32) == 0)
751
for (int i = 0; i <
_bits
.Length; i++)
753
bits32[i * 2] = (uint)
_bits
[i];
756
bits32[i * 2 + 1] = (uint)(
_bits
[i] >> 32);
775
if (
_bits
is null)
785
int iu =
_bits
.Length - 1;
786
return BitOperations.IsPow2(
_bits
[iu]) && !
_bits
.AsSpan(0, iu).ContainsAnyExcept(0u);
792
public bool IsOne => _sign == 1 &&
_bits
is null;
794
public bool IsEven =>
_bits
is null ? (_sign & 1) == 0 : (
_bits
[0] & 1) == 0;
884
return new BigInteger((int)NumericsHelpers.Abs(value._sign), value.
_bits
);
914
bool trivialDividend = dividend.
_bits
is null;
915
bool trivialDivisor = divisor.
_bits
is null;
933
Debug.Assert(dividend.
_bits
is not null);
937
int size = dividend.
_bits
.Length;
942
BigIntegerCalculator.Divide(dividend.
_bits
, NumericsHelpers.Abs(divisor._sign), quotient, out nuint rest);
948
Debug.Assert(divisor.
_bits
is not null);
950
if (dividend.
_bits
.Length < divisor.
_bits
.Length)
957
int size = dividend.
_bits
.Length;
960
size = dividend.
_bits
.Length - divisor.
_bits
.Length + 1;
963
BigIntegerCalculator.Divide(dividend.
_bits
, divisor.
_bits
, quotient, rest);
1002
if (value.
_bits
is null)
1014
h = value.
_bits
[^1];
1015
m = value.
_bits
.Length > 1 ? value.
_bits
[^2] : 0;
1018
b = (long)value.
_bits
.Length * 64 - c;
1025
h = (uint)value.
_bits
[^1];
1026
m = value.
_bits
.Length > 1 ? (uint)value.
_bits
[^2] : 0;
1027
l = value.
_bits
.Length > 2 ? (uint)value.
_bits
[^3] : 0;
1031
b = (long)value.
_bits
.Length * 32 - c;
1049
bool trivialLeft = left.
_bits
is null;
1050
bool trivialRight = right.
_bits
is null;
1059
Debug.Assert(right.
_bits
is not null);
1061
? BigIntegerCalculator.Gcd(right.
_bits
, NumericsHelpers.Abs(left._sign))
1062
: new BigInteger(+1, right.
_bits
);
1067
Debug.Assert(left.
_bits
is not null);
1069
? BigIntegerCalculator.Gcd(left.
_bits
, NumericsHelpers.Abs(right._sign))
1070
: new BigInteger(+1, left.
_bits
);
1073
Debug.Assert(left.
_bits
is not null && right.
_bits
is not null);
1075
return BigIntegerCalculator.Compare(left.
_bits
, right.
_bits
) < 0
1076
? GreatestCommonDivisor(right.
_bits
, left.
_bits
)
1077
: GreatestCommonDivisor(left.
_bits
, right.
_bits
);
1130
bool trivialValue = value.
_bits
is null;
1131
bool trivialExponent = exponent.
_bits
is null;
1132
bool trivialModulus = modulus.
_bits
is null;
1139
trivialValue ? BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), exponent.
_bits
!, NumericsHelpers.Abs(modulus._sign)) :
1140
trivialExponent ? BigIntegerCalculator.Pow(value.
_bits
!, NumericsHelpers.Abs(exponent._sign), NumericsHelpers.Abs(modulus._sign)) :
1141
BigIntegerCalculator.Pow(value.
_bits
!, exponent.
_bits
!, NumericsHelpers.Abs(modulus._sign));
1147
int size = (modulus.
_bits
?.Length ?? 1) << 1;
1153
BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), NumericsHelpers.Abs(exponent._sign), modulus.
_bits
!, bits);
1157
BigIntegerCalculator.Pow(NumericsHelpers.Abs(value._sign), exponent.
_bits
!, modulus.
_bits
!, bits);
1162
BigIntegerCalculator.Pow(value.
_bits
!, NumericsHelpers.Abs(exponent._sign), modulus.
_bits
!, bits);
1166
BigIntegerCalculator.Pow(value.
_bits
!, exponent.
_bits
!, modulus.
_bits
!, bits);
1191
bool trivialValue = value.
_bits
is null;
1222
int size = BigIntegerCalculator.PowBound(power, value.
_bits
!.Length);
1225
BigIntegerCalculator.Pow(value.
_bits
, power, bits);
1235
if (
_bits
is null)
1241
hash.AddBytes(MemoryMarshal.AsBytes(
_bits
.AsSpan()));
1253
if (
_bits
is null)
1260
if ((_sign ^ other) < 0 || (cu =
_bits
.Length) > maxLimbs)
1269
return
_bits
[0] == uu;
1274
? (uint)
_bits
[0] == uu
1275
: ((ulong)(uint)
_bits
[1] << 32 | (uint)
_bits
[0]) == uu;
1287
if (
_bits
is null)
1292
int cu =
_bits
.Length;
1301
return
_bits
[0] == other;
1306
? (uint)
_bits
[0] == other
1307
: ((ulong)(uint)
_bits
[1] << 32 | (uint)
_bits
[0]) == other;
1313
return _sign == other._sign &&
_bits
.AsSpan().SequenceEqual(other.
_bits
);
1318
if (
_bits
is null)
1325
if ((_sign ^ other) < 0 || (cu =
_bits
.Length) > maxLimbs)
1335
uuTmp =
_bits
[0];
1340
? ((ulong)(uint)
_bits
[1] << 32 | (uint)
_bits
[0])
1341
: (uint)
_bits
[0];
1355
if (
_bits
is null)
1360
int cu =
_bits
.Length;
1371
uuTmp =
_bits
[0];
1376
? ((ulong)(uint)
_bits
[1] << 32 | (uint)
_bits
[0])
1377
: (uint)
_bits
[0];
1392
if (
_bits
is null)
1395
other.
_bits
is not null ? -other._sign :
1401
if (other.
_bits
is null)
1406
int bitsResult = BigIntegerCalculator.Compare(
_bits
, other.
_bits
);
1570
nuint[]? bits =
_bits
;
1746
Debug.Assert(
_bits
is null || _sign == 0 ? buffer.Length == 2 : buffer.Length >=
_bits
.Length + 1);
1750
if (
_bits
is null)
1757
_bits
.CopyTo(buffer);
1758
buffer = buffer.Slice(0,
_bits
.Length + 1);
1821
if ((
_bits
is null) || (
_bits
.Length <= 4))
1836
highBits =
_bits
[^1];
1837
lowBitsCount =
_bits
.Length - 1;
1841
highBits = ((ulong)
_bits
[^1] << BitsPerUInt32) + (uint)
_bits
[^2];
1842
lowBitsCount =
_bits
.Length - 2;
1948
if (left.
_bits
is null && right.
_bits
is null)
1954
? Add(left.
_bits
, left._sign, right.
_bits
, -right._sign)
1955
: Subtract(left.
_bits
, left._sign, right.
_bits
, right._sign);
2026
if (value.
_bits
is null)
2044
nuint[]? bits = value.
_bits
;
2162
if (value.
_bits
is null)
2167
if (value.
_bits
.Length > 1)
2175
return checked((int)value.
_bits
[0]);
2178
if (value.
_bits
[0] > UInt32HighBit)
2184
return -(int)value.
_bits
[0];
2189
if (value.
_bits
is null)
2194
int len = value.
_bits
.Length;
2205
uu = value.
_bits
[0];
2210
? ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2211
: (uint)value.
_bits
[0];
2229
if (value.
_bits
is null)
2234
int len = value.
_bits
.Length;
2246
uu = len > 1 ? new UInt128(value.
_bits
[1], value.
_bits
[0]) : (UInt128)(ulong)value.
_bits
[0];
2251
((ulong)((len > 3) ? (uint)value.
_bits
[3] : 0) << 32 | (uint)value.
_bits
[2]),
2252
((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2258
? (UInt128)((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2259
: (UInt128)(uint)value.
_bits
[0];
2289
if (value.
_bits
is null)
2295
return value.
_bits
.Length <= 1 && value._sign >= 0
2296
? checked((uint)value.
_bits
[0])
2304
if (value.
_bits
is null)
2309
int len = value.
_bits
.Length;
2318
return value.
_bits
[0];
2322
? ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2323
: (uint)value.
_bits
[0];
2332
if (value.
_bits
is null)
2337
int len = value.
_bits
.Length;
2348
? new UInt128(value.
_bits
[1], value.
_bits
[0])
2349
: (UInt128)(ulong)value.
_bits
[0];
2354
((ulong)((len > 3) ? (uint)value.
_bits
[3] : 0) << 32 | (uint)value.
_bits
[2]),
2355
((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2360
return ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0]);
2363
return (uint)value.
_bits
[0];
2567
left.
_bits
is null && right.
_bits
is null ? (BigInteger)(left._sign & right._sign) :
2582
return left.
_bits
is null && right.
_bits
is null
2588
left.
_bits
is null && right.
_bits
is null
2598
int xLen = left.
_bits
?.Length ?? 1;
2599
int yLen = right.
_bits
?.Length ?? 1;
2617
int xLen = left.
_bits
?.Length ?? 1;
2618
int yLen = right.
_bits
?.Length ?? 1;
2627
int xLen = left.
_bits
?.Length ?? 1;
2628
int yLen = right.
_bits
?.Length ?? 1;
2638
left.
_bits
, left._sign,
2639
right.
_bits
, right._sign,
2668
if (value.
_bits
is null)
2674
ReadOnlySpan<nuint> bits = value.
_bits
;
2762
if (value.
_bits
is null)
2775
ReadOnlySpan<nuint> bits = value.
_bits
;
2815
if (value.
_bits
is null)
2825
int size = value.
_bits
.Length + 1;
2828
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
2835
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
2837
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
2845
public static BigInteger operator -(BigInteger value) => new BigInteger(-value._sign, value.
_bits
);
2851
if (value.
_bits
is null)
2860
int size = value.
_bits
.Length + 1;
2863
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
2869
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
2871
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
2881
if (value.
_bits
is null)
2890
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
2892
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
2898
int size = value.
_bits
.Length + 1;
2901
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
2911
if (left.
_bits
is null && right.
_bits
is null)
2917
? Subtract(left.
_bits
, left._sign, right.
_bits
, -right._sign)
2918
: Add(left.
_bits
, left._sign, right.
_bits
, right._sign);
2922
left.
_bits
is null && right.
_bits
is null
2924
: Multiply(left.
_bits
, left._sign, right.
_bits
, right._sign);
2983
bool trivialDividend = dividend.
_bits
is null;
2984
bool trivialDivisor = divisor.
_bits
is null;
3000
Debug.Assert(dividend.
_bits
is not null);
3002
int size = dividend.
_bits
.Length;
3006
BigIntegerCalculator.Divide(dividend.
_bits
, NumericsHelpers.Abs(divisor._sign), quotient);
3015
Debug.Assert(dividend.
_bits
is not null && divisor.
_bits
is not null);
3017
if (dividend.
_bits
.Length < divisor.
_bits
.Length)
3023
int size = dividend.
_bits
.Length - divisor.
_bits
.Length + 1;
3026
BigIntegerCalculator.Divide(dividend.
_bits
, divisor.
_bits
, quotient);
3037
bool trivialDividend = dividend.
_bits
is null;
3038
bool trivialDivisor = divisor.
_bits
is null;
3054
Debug.Assert(dividend.
_bits
is not null);
3055
nuint remainder = BigIntegerCalculator.Remainder(dividend.
_bits
, NumericsHelpers.Abs(divisor._sign));
3059
Debug.Assert(dividend.
_bits
is not null && divisor.
_bits
is not null);
3061
if (dividend.
_bits
.Length < divisor.
_bits
.Length)
3066
int size = dividend.
_bits
.Length;
3069
BigIntegerCalculator.Remainder(dividend.
_bits
, divisor.
_bits
, bits);
3159
nuint[]? bits =
_bits
;
3195
if (
_bits
is not null)
3200
Debug.Assert(
_bits
.Length > 0);
3202
Debug.Assert(
_bits
.Length > 1 ||
_bits
[0] > int.MaxValue);
3204
Debug.Assert(
_bits
[^1] != 0);
3206
Debug.Assert(
_bits
.Length <= MaxLength);
3237
if (value.
_bits
is null)
3266
if (value.
_bits
is null)
3282
return BitOperations.LeadingZeroCount(value.
_bits
[^1]) & 31;
3288
if (value.
_bits
is null)
3299
for (int i = 0; i < value.
_bits
.Length; i++)
3301
nuint part = value.
_bits
[i];
3310
int firstNonZero = value.
_bits
.AsSpan().IndexOfAnyExcept((nuint)0);
3316
part = ~value.
_bits
[i] + 1;
3320
while (i < value.
_bits
.Length)
3323
part = ~value.
_bits
[i];
3331
if (Environment.Is64BitProcess && (uint)(value.
_bits
[^1] >> BitsPerUInt32) == 0)
3350
if (value.
_bits
is null)
3358
return Rotate(value.
_bits
, neg, rotateAmount);
3371
if (value.
_bits
is null)
3379
return Rotate(value.
_bits
, neg, -(long)rotateAmount);
3641
if (value.
_bits
is null)
3651
nuint part = value.
_bits
[0];
3653
for (int i = 1; (part == 0) && (i < value.
_bits
.Length); i++)
3655
part = value.
_bits
[i];
3681
nuint[]? bits =
_bits
;
3721
nuint[]? bits =
_bits
;
3799
nuint[]? bits =
_bits
;
3874
nuint[]? bits =
_bits
;
3925
return value.
_bits
is null
3927
: (BigInteger)(((long)value.
_bits
.Length * BigIntegerCalculator.BitsPerLimb - 1) ^ BitOperations.LeadingZeroCount(value.
_bits
[^1]));
3972
if (value.
_bits
is null)
3979
if (sign.
_bits
is null)
3996
return value.
_bits
is null
4074
return value.
_bits
is null
4076
: (value.
_bits
[0] & 1) == 0;
4109
return value.
_bits
is null
4111
: (value.
_bits
[0] & 1) != 0;
4660
if (value.
_bits
is not null)
4677
if (value.
_bits
is not null)
4719
if (value.
_bits
is not null)
4736
if (value.
_bits
is not null)
4780
if (value.
_bits
is not null)
4803
if (value.
_bits
is not null)
4859
if (value.
_bits
is not null)
4861
nuint bits = value.
_bits
[0];
4882
if (value.
_bits
is not null)
4884
nuint bits = value.
_bits
[0];
4930
if (value.
_bits
is not null)
4932
actualResult = IsNegative(value) ? (short)(~value.
_bits
[0] + 1) : (short)value.
_bits
[0];
4946
if (value.
_bits
is not null)
4948
actualResult = IsNegative(value) ? (int)(~value.
_bits
[0] + 1) : (int)value.
_bits
[0];
4962
if (value.
_bits
is not null)
4968
bits = value.
_bits
[0];
4974
if (value.
_bits
.Length >= 2)
4976
bits = value.
_bits
[1];
4980
bits |= value.
_bits
[0];
5002
if (value.
_bits
is not null)
5009
lowerBits = value.
_bits
[0];
5011
if (value.
_bits
.Length >= 2)
5013
upperBits = value.
_bits
[1];
5018
if (value.
_bits
.Length >= 4)
5020
upperBits = value.
_bits
[3];
5024
if (value.
_bits
.Length >= 3)
5026
upperBits |= value.
_bits
[2];
5029
if (value.
_bits
.Length >= 2)
5031
lowerBits = value.
_bits
[1];
5035
lowerBits |= value.
_bits
[0];
5059
if (value.
_bits
is not null)
5061
nuint bits = value.
_bits
[0];
5088
if (value.
_bits
is not null)
5090
actualResult = IsNegative(value) ? (sbyte)(~value.
_bits
[0] + 1) : (sbyte)value.
_bits
[0];
5110
if (value.
_bits
is not null)
5112
nuint bits = value.
_bits
[0];
5133
if (value.
_bits
is not null)
5135
uint bits = (uint)value.
_bits
[0];
5156
if (value.
_bits
is not null)
5162
bits = value.
_bits
[0];
5168
if (value.
_bits
.Length >= 2)
5170
bits = value.
_bits
[1];
5174
bits |= value.
_bits
[0];
5196
if (value.
_bits
is not null)
5203
lowerBits = value.
_bits
[0];
5205
if (value.
_bits
.Length >= 2)
5207
upperBits = value.
_bits
[1];
5212
if (value.
_bits
.Length >= 4)
5214
upperBits = value.
_bits
[3];
5218
if (value.
_bits
.Length >= 3)
5220
upperBits |= value.
_bits
[2];
5223
if (value.
_bits
.Length >= 2)
5225
lowerBits = value.
_bits
[1];
5229
lowerBits |= value.
_bits
[0];
5253
if (value.
_bits
is not null)
5255
nuint bits = value.
_bits
[0];
5310
if (value.
_bits
is null)
5322
ReadOnlySpan<nuint> bits = value.
_bits
;