Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ToUInt32Span()

ReadOnlySpan< uint > System.Numerics.BigInteger.ToUInt32Span ( Span< uint > scratch)
inlineprivate

Definition at line 1235 of file BigInteger.cs.

1236 {
1237 if (_bits == null && _sign == 0)
1238 {
1239 scratch[0] = 0u;
1240 return scratch.Slice(0, 1);
1241 }
1242 Span<uint> span = scratch;
1243 bool flag = true;
1244 uint num;
1245 if (_bits == null)
1246 {
1247 span[0] = (uint)_sign;
1248 span = span.Slice(0, 1);
1249 num = ((_sign < 0) ? uint.MaxValue : 0u);
1250 }
1251 else if (_sign == -1)
1252 {
1253 if (span.Length >= _bits.Length)
1254 {
1255 _bits.AsSpan().CopyTo(span);
1256 span = span.Slice(0, _bits.Length);
1257 }
1258 else
1259 {
1260 span = (uint[])_bits.Clone();
1261 }
1262 NumericsHelpers.DangerousMakeTwosComplement(span);
1263 num = uint.MaxValue;
1264 }
1265 else
1266 {
1267 span = _bits;
1268 num = 0u;
1269 flag = false;
1270 }
1271 int num2 = span.Length - 1;
1272 while (num2 > 0 && span[num2] == num)
1273 {
1274 num2--;
1275 }
1276 bool flag2 = (span[num2] & 0x80000000u) != (num & 0x80000000u);
1277 int num3 = num2 + 1 + (flag2 ? 1 : 0);
1278 bool flag3 = true;
1279 if (num3 <= scratch.Length)
1280 {
1281 scratch = scratch.Slice(0, num3);
1282 flag3 = !flag;
1283 }
1284 else
1285 {
1286 scratch = new uint[num3];
1287 }
1288 if (flag3)
1289 {
1290 span.Slice(0, num2 + 1).CopyTo(scratch);
1291 }
1292 if (flag2)
1293 {
1294 scratch[^1] = num;
1295 }
1296 return scratch;
1297 }
readonly uint[] _bits
Definition BigInteger.cs:20

References System.Numerics.BigInteger._bits, System.Numerics.BigInteger._sign, System.Numerics.NumericsHelpers.DangerousMakeTwosComplement(), System.Span< T >.Length, and System.Span< T >.Slice().

Referenced by System.Numerics.BigInteger.operator&(), System.Numerics.BigInteger.operator^(), and System.Numerics.BigInteger.operator|().