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

◆ Square() [1/2]

static unsafe void System.Numerics.BigIntegerCalculator.Square ( uint * value,
int valueLength,
uint * bits,
int bitsLength )
inlinestaticprivate

Definition at line 1152 of file BigIntegerCalculator.cs.

1153 {
1154 if (valueLength < SquareThreshold)
1155 {
1156 for (int i = 0; i < valueLength; i++)
1157 {
1158 ulong num = 0uL;
1159 for (int j = 0; j < i; j++)
1160 {
1161 ulong num2 = bits[i + j] + num;
1162 ulong num3 = (ulong)value[j] * (ulong)value[i];
1163 bits[i + j] = (uint)(num2 + (num3 << 1));
1164 num = num3 + (num2 >> 1) >> 31;
1165 }
1166 ulong num4 = (ulong)((long)value[i] * (long)value[i]) + num;
1167 bits[i + i] = (uint)num4;
1168 bits[i + i + 1] = (uint)(num4 >> 32);
1169 }
1170 return;
1171 }
1172 int num5 = valueLength >> 1;
1173 int num6 = num5 << 1;
1174 int num7 = num5;
1175 uint* ptr = value + num5;
1176 int num8 = valueLength - num5;
1177 int num9 = num6;
1178 uint* ptr2 = bits + num6;
1179 int num10 = bitsLength - num6;
1180 Square(value, num7, bits, num9);
1181 Square(ptr, num8, ptr2, num10);
1182 int num11 = num8 + 1;
1183 int num12 = num11 + num11;
1184 if (num12 < AllocationThreshold)
1185 {
1186 uint* ptr3 = stackalloc uint[num11];
1187 new Span<uint>(ptr3, num11).Clear();
1188 uint* ptr4 = stackalloc uint[num12];
1189 new Span<uint>(ptr4, num12).Clear();
1190 Add(ptr, num8, value, num7, ptr3, num11);
1191 Square(ptr3, num11, ptr4, num12);
1192 SubtractCore(ptr2, num10, bits, num9, ptr4, num12);
1193 AddSelf(bits + num5, bitsLength - num5, ptr4, num12);
1194 return;
1195 }
1196 fixed (uint* ptr5 = new uint[num11])
1197 {
1198 fixed (uint* ptr6 = new uint[num12])
1199 {
1200 Add(ptr, num8, value, num7, ptr5, num11);
1201 Square(ptr5, num11, ptr6, num12);
1202 SubtractCore(ptr2, num10, bits, num9, ptr6, num12);
1203 AddSelf(bits + num5, bitsLength - num5, ptr6, num12);
1204 }
1205 }
1206 }
static unsafe void SubtractCore(uint *left, int leftLength, uint *right, int rightLength, uint *core, int coreLength)
static unsafe uint[] Square(uint[] value)
static unsafe void AddSelf(uint *left, int leftLength, uint *right, int rightLength)

References System.Add, System.Numerics.BigIntegerCalculator.AddSelf(), System.Numerics.BigIntegerCalculator.AllocationThreshold, System.Span< T >.Clear(), System.Numerics.BigIntegerCalculator.Square(), System.Numerics.BigIntegerCalculator.SquareThreshold, System.Numerics.BigIntegerCalculator.SubtractCore(), and System.value.