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

◆ VarDecFromR4()

static void System.Decimal.DecCalc.VarDecFromR4 ( float input,
out DecCalc result )
inlinestaticpackage

Definition at line 1273 of file Decimal.cs.

1274 {
1275 result = default(DecCalc);
1276 int num = (int)(GetExponent(input) - 126);
1277 if (num < -94)
1278 {
1279 return;
1280 }
1281 if (num > 96)
1282 {
1283 Number.ThrowOverflowException(TypeCode.Decimal);
1284 }
1285 uint num2 = 0u;
1286 if (input < 0f)
1287 {
1288 input = 0f - input;
1289 num2 = 2147483648u;
1290 }
1291 double num3 = input;
1292 int num4 = 6 - (num * 19728 >> 16);
1293 if (num4 >= 0)
1294 {
1295 if (num4 > 28)
1296 {
1297 num4 = 28;
1298 }
1300 }
1301 else if (num4 != -1 || num3 >= 10000000.0)
1302 {
1304 }
1305 else
1306 {
1307 num4 = 0;
1308 }
1309 if (num3 < 1000000.0 && num4 < 28)
1310 {
1311 num3 *= 10.0;
1312 num4++;
1313 }
1314 uint num5;
1315 if (Sse41.IsSupported)
1316 {
1317 num5 = (uint)(int)Math.Round(num3);
1318 }
1319 else
1320 {
1321 num5 = (uint)(int)num3;
1322 num3 -= (double)(int)num5;
1323 if (num3 > 0.5 || (num3 == 0.5 && (num5 & (true ? 1u : 0u)) != 0))
1324 {
1325 num5++;
1326 }
1327 }
1328 if (num5 == 0)
1329 {
1330 return;
1331 }
1332 if (num4 < 0)
1333 {
1334 num4 = -num4;
1335 if (num4 < 10)
1336 {
1338 }
1339 else if (num4 > 18)
1340 {
1341 ulong a = UInt32x32To64(num5, s_powers10[num4 - 18]);
1342 UInt64x64To128(a, 1000000000000000000uL, ref result);
1343 }
1344 else
1345 {
1346 ulong num6 = UInt32x32To64(num5, s_powers10[num4 - 9]);
1347 ulong num7 = UInt32x32To64(1000000000u, (uint)(num6 >> 32));
1348 num6 = UInt32x32To64(1000000000u, (uint)num6);
1349 result.Low = (uint)num6;
1350 num7 += num6 >> 32;
1351 result.Mid = (uint)num7;
1352 num7 >>= 32;
1353 result.High = (uint)num7;
1354 }
1355 }
1356 else
1357 {
1358 int num8 = num4;
1359 if (num8 > 6)
1360 {
1361 num8 = 6;
1362 }
1363 if ((num5 & 0xF) == 0 && num8 >= 4)
1364 {
1365 uint num9 = num5 / 10000;
1366 if (num5 == num9 * 10000)
1367 {
1368 num5 = num9;
1369 num4 -= 4;
1370 num8 -= 4;
1371 }
1372 }
1373 if ((num5 & 3) == 0 && num8 >= 2)
1374 {
1375 uint num10 = num5 / 100;
1376 if (num5 == num10 * 100)
1377 {
1378 num5 = num10;
1379 num4 -= 2;
1380 num8 -= 2;
1381 }
1382 }
1383 if ((num5 & 1) == 0 && num8 >= 1)
1384 {
1385 uint num11 = num5 / 10;
1386 if (num5 == num11 * 10)
1387 {
1388 num5 = num11;
1389 num4--;
1390 }
1391 }
1392 num2 |= (uint)(num4 << 16);
1393 result.Low = num5;
1394 }
1396 }
static void UInt64x64To128(ulong a, ulong b, ref DecCalc result)
Definition Decimal.cs:305
static readonly uint[] s_powers10
Definition Decimal.cs:205
static unsafe uint GetExponent(float f)
Definition Decimal.cs:290
static readonly double[] s_doublePowers10
Definition Decimal.cs:213
static ulong UInt32x32To64(uint a, uint b)
Definition Decimal.cs:300

References System.Runtime.Serialization.Dictionary, System.Decimal.DecCalc.GetExponent(), System.input, System.Runtime.Intrinsics.X86.Sse41.IsSupported, System.Math.Round(), System.Decimal.DecCalc.s_doublePowers10, System.Decimal.DecCalc.s_powers10, System.Number.ThrowOverflowException(), System.Decimal.DecCalc.UInt32x32To64(), and System.Decimal.DecCalc.UInt64x64To128().

Referenced by System.Decimal.Decimal().