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];
371 references to _bits
System.Runtime.Numerics (371)
System\Number.BigInteger.cs (3)
832
if (value.
_bits
== null)
879
int base1E9BufferLength = (int)(value.
_bits
.Length * digitRatio) + 1;
883
BigIntegerToBase1E9(value.
_bits
, base1E9Buffer, out int written);
System\Numerics\BigInteger.cs (368)
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)
2037
nuint[]? bits = value.
_bits
;
2070
nuint[]? bits = value.
_bits
;
2204
nuint[]? bits = value.
_bits
;
2223
nuint[]? bits = value.
_bits
;
2246
if (value.
_bits
is null)
2251
if (value.
_bits
.Length > 1)
2259
return checked((int)value.
_bits
[0]);
2262
if (value.
_bits
[0] > UInt32HighBit)
2268
return -(int)value.
_bits
[0];
2273
if (value.
_bits
is null)
2278
int len = value.
_bits
.Length;
2289
uu = value.
_bits
[0];
2294
? ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2295
: (uint)value.
_bits
[0];
2313
if (value.
_bits
is null)
2318
int len = value.
_bits
.Length;
2330
uu = len > 1 ? new UInt128(value.
_bits
[1], value.
_bits
[0]) : (UInt128)(ulong)value.
_bits
[0];
2335
((ulong)((len > 3) ? (uint)value.
_bits
[3] : 0) << 32 | (uint)value.
_bits
[2]),
2336
((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2342
? (UInt128)((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2343
: (UInt128)(uint)value.
_bits
[0];
2368
nuint[]? bits = value.
_bits
;
2398
if (value.
_bits
is null)
2404
return value.
_bits
.Length <= 1 && value._sign >= 0
2405
? checked((uint)value.
_bits
[0])
2413
if (value.
_bits
is null)
2418
int len = value.
_bits
.Length;
2427
return value.
_bits
[0];
2431
? ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2432
: (uint)value.
_bits
[0];
2441
if (value.
_bits
is null)
2446
int len = value.
_bits
.Length;
2457
? new UInt128(value.
_bits
[1], value.
_bits
[0])
2458
: (UInt128)(ulong)value.
_bits
[0];
2463
((ulong)((len > 3) ? (uint)value.
_bits
[3] : 0) << 32 | (uint)value.
_bits
[2]),
2464
((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0])
2469
return ((ulong)(uint)value.
_bits
[1] << 32 | (uint)value.
_bits
[0]);
2472
return (uint)value.
_bits
[0];
2676
left.
_bits
is null && right.
_bits
is null ? (BigInteger)(left._sign & right._sign) :
2691
return left.
_bits
is null && right.
_bits
is null
2697
left.
_bits
is null && right.
_bits
is null
2707
int xLen = left.
_bits
?.Length ?? 1;
2708
int yLen = right.
_bits
?.Length ?? 1;
2726
int xLen = left.
_bits
?.Length ?? 1;
2727
int yLen = right.
_bits
?.Length ?? 1;
2736
int xLen = left.
_bits
?.Length ?? 1;
2737
int yLen = right.
_bits
?.Length ?? 1;
2747
left.
_bits
, left._sign,
2748
right.
_bits
, right._sign,
2777
if (value.
_bits
is null)
2783
ReadOnlySpan<nuint> bits = value.
_bits
;
2871
if (value.
_bits
is null)
2884
ReadOnlySpan<nuint> bits = value.
_bits
;
2924
if (value.
_bits
is null)
2934
int size = value.
_bits
.Length + 1;
2937
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
2944
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
2946
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
2954
public static BigInteger operator -(BigInteger value) => new BigInteger(-value._sign, value.
_bits
);
2960
if (value.
_bits
is null)
2969
int size = value.
_bits
.Length + 1;
2972
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
2978
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
2980
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
2990
if (value.
_bits
is null)
2999
Span<nuint> bits = RentedBuffer.Create(value.
_bits
.Length, out RentedBuffer bitsBuffer);
3001
BigIntegerCalculator.Subtract(value.
_bits
, 1, bits);
3007
int size = value.
_bits
.Length + 1;
3010
BigIntegerCalculator.Add(value.
_bits
, 1, bits);
3020
if (left.
_bits
is null && right.
_bits
is null)
3026
? Subtract(left.
_bits
, left._sign, right.
_bits
, -right._sign)
3027
: Add(left.
_bits
, left._sign, right.
_bits
, right._sign);
3031
left.
_bits
is null && right.
_bits
is null
3033
: Multiply(left.
_bits
, left._sign, right.
_bits
, right._sign);
3092
bool trivialDividend = dividend.
_bits
is null;
3093
bool trivialDivisor = divisor.
_bits
is null;
3109
Debug.Assert(dividend.
_bits
is not null);
3111
int size = dividend.
_bits
.Length;
3115
BigIntegerCalculator.Divide(dividend.
_bits
, NumericsHelpers.Abs(divisor._sign), quotient);
3124
Debug.Assert(dividend.
_bits
is not null && divisor.
_bits
is not null);
3126
if (dividend.
_bits
.Length < divisor.
_bits
.Length)
3132
int size = dividend.
_bits
.Length - divisor.
_bits
.Length + 1;
3135
BigIntegerCalculator.Divide(dividend.
_bits
, divisor.
_bits
, quotient);
3146
bool trivialDividend = dividend.
_bits
is null;
3147
bool trivialDivisor = divisor.
_bits
is null;
3163
Debug.Assert(dividend.
_bits
is not null);
3164
nuint remainder = BigIntegerCalculator.Remainder(dividend.
_bits
, NumericsHelpers.Abs(divisor._sign));
3168
Debug.Assert(dividend.
_bits
is not null && divisor.
_bits
is not null);
3170
if (dividend.
_bits
.Length < divisor.
_bits
.Length)
3175
int size = dividend.
_bits
.Length;
3178
BigIntegerCalculator.Remainder(dividend.
_bits
, divisor.
_bits
, bits);
3268
nuint[]? bits =
_bits
;
3304
if (
_bits
is not null)
3309
Debug.Assert(
_bits
.Length > 0);
3311
Debug.Assert(
_bits
.Length > 1 ||
_bits
[0] > int.MaxValue);
3313
Debug.Assert(
_bits
[^1] != 0);
3315
Debug.Assert(
_bits
.Length <= MaxLength);
3346
if (value.
_bits
is null)
3375
if (value.
_bits
is null)
3391
return BitOperations.LeadingZeroCount(value.
_bits
[^1]) & 31;
3397
if (value.
_bits
is null)
3408
for (int i = 0; i < value.
_bits
.Length; i++)
3410
nuint part = value.
_bits
[i];
3419
int firstNonZero = value.
_bits
.AsSpan().IndexOfAnyExcept((nuint)0);
3425
part = ~value.
_bits
[i] + 1;
3429
while (i < value.
_bits
.Length)
3432
part = ~value.
_bits
[i];
3440
if (Environment.Is64BitProcess && (uint)(value.
_bits
[^1] >> BitsPerUInt32) == 0)
3459
if (value.
_bits
is null)
3467
return Rotate(value.
_bits
, neg, rotateAmount);
3480
if (value.
_bits
is null)
3488
return Rotate(value.
_bits
, neg, -(long)rotateAmount);
3750
if (value.
_bits
is null)
3760
nuint part = value.
_bits
[0];
3762
for (int i = 1; (part == 0) && (i < value.
_bits
.Length); i++)
3764
part = value.
_bits
[i];
3790
nuint[]? bits =
_bits
;
3830
nuint[]? bits =
_bits
;
3908
nuint[]? bits =
_bits
;
3983
nuint[]? bits =
_bits
;
4034
return value.
_bits
is null
4036
: (BigInteger)(((long)value.
_bits
.Length * BigIntegerCalculator.BitsPerLimb - 1) ^ BitOperations.LeadingZeroCount(value.
_bits
[^1]));
4081
if (value.
_bits
is null)
4088
if (sign.
_bits
is null)
4105
return value.
_bits
is null
4183
return value.
_bits
is null
4185
: (value.
_bits
[0] & 1) == 0;
4218
return value.
_bits
is null
4220
: (value.
_bits
[0] & 1) != 0;
4769
if (value.
_bits
is not null)
4786
if (value.
_bits
is not null)
4828
if (value.
_bits
is not null)
4845
if (value.
_bits
is not null)
4889
if (value.
_bits
is not null)
4912
if (value.
_bits
is not null)
4968
if (value.
_bits
is not null)
4970
nuint bits = value.
_bits
[0];
4991
if (value.
_bits
is not null)
4993
nuint bits = value.
_bits
[0];
5039
if (value.
_bits
is not null)
5041
actualResult = IsNegative(value) ? (short)(~value.
_bits
[0] + 1) : (short)value.
_bits
[0];
5055
if (value.
_bits
is not null)
5057
actualResult = IsNegative(value) ? (int)(~value.
_bits
[0] + 1) : (int)value.
_bits
[0];
5071
if (value.
_bits
is not null)
5077
bits = value.
_bits
[0];
5083
if (value.
_bits
.Length >= 2)
5085
bits = value.
_bits
[1];
5089
bits |= value.
_bits
[0];
5111
if (value.
_bits
is not null)
5118
lowerBits = value.
_bits
[0];
5120
if (value.
_bits
.Length >= 2)
5122
upperBits = value.
_bits
[1];
5127
if (value.
_bits
.Length >= 4)
5129
upperBits = value.
_bits
[3];
5133
if (value.
_bits
.Length >= 3)
5135
upperBits |= value.
_bits
[2];
5138
if (value.
_bits
.Length >= 2)
5140
lowerBits = value.
_bits
[1];
5144
lowerBits |= value.
_bits
[0];
5168
if (value.
_bits
is not null)
5170
nuint bits = value.
_bits
[0];
5197
if (value.
_bits
is not null)
5199
actualResult = IsNegative(value) ? (sbyte)(~value.
_bits
[0] + 1) : (sbyte)value.
_bits
[0];
5219
if (value.
_bits
is not null)
5221
nuint bits = value.
_bits
[0];
5242
if (value.
_bits
is not null)
5244
uint bits = (uint)value.
_bits
[0];
5265
if (value.
_bits
is not null)
5271
bits = value.
_bits
[0];
5277
if (value.
_bits
.Length >= 2)
5279
bits = value.
_bits
[1];
5283
bits |= value.
_bits
[0];
5305
if (value.
_bits
is not null)
5312
lowerBits = value.
_bits
[0];
5314
if (value.
_bits
.Length >= 2)
5316
upperBits = value.
_bits
[1];
5321
if (value.
_bits
.Length >= 4)
5323
upperBits = value.
_bits
[3];
5327
if (value.
_bits
.Length >= 3)
5329
upperBits |= value.
_bits
[2];
5332
if (value.
_bits
.Length >= 2)
5334
lowerBits = value.
_bits
[1];
5338
lowerBits |= value.
_bits
[0];
5362
if (value.
_bits
is not null)
5364
nuint bits = value.
_bits
[0];
5419
if (value.
_bits
is null)
5431
ReadOnlySpan<nuint> bits = value.
_bits
;