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

◆ VarDecFromR8()

static void System.Decimal.DecCalc.VarDecFromR8 ( double input,
out DecCalc result )
inlinestaticpackage

Definition at line 1398 of file Decimal.cs.

1399 {
1400 result = default(DecCalc);
1401 int num = (int)(GetExponent(input) - 1022);
1402 if (num < -94)
1403 {
1404 return;
1405 }
1406 if (num > 96)
1407 {
1408 Number.ThrowOverflowException(TypeCode.Decimal);
1409 }
1410 uint num2 = 0u;
1411 if (input < 0.0)
1412 {
1413 input = 0.0 - input;
1414 num2 = 2147483648u;
1415 }
1416 double num3 = input;
1417 int num4 = 14 - (num * 19728 >> 16);
1418 if (num4 >= 0)
1419 {
1420 if (num4 > 28)
1421 {
1422 num4 = 28;
1423 }
1425 }
1426 else if (num4 != -1 || num3 >= 1000000000000000.0)
1427 {
1429 }
1430 else
1431 {
1432 num4 = 0;
1433 }
1434 if (num3 < 100000000000000.0 && num4 < 28)
1435 {
1436 num3 *= 10.0;
1437 num4++;
1438 }
1439 ulong num5;
1440 if (Sse41.IsSupported)
1441 {
1442 num5 = (ulong)(long)Math.Round(num3);
1443 }
1444 else
1445 {
1446 num5 = (ulong)(long)num3;
1447 num3 -= (double)(long)num5;
1448 if (num3 > 0.5 || (num3 == 0.5 && (num5 & 1) != 0L))
1449 {
1450 num5++;
1451 }
1452 }
1453 if (num5 == 0L)
1454 {
1455 return;
1456 }
1457 if (num4 < 0)
1458 {
1459 num4 = -num4;
1460 if (num4 < 10)
1461 {
1462 uint b = s_powers10[num4];
1463 ulong num6 = UInt32x32To64((uint)num5, b);
1464 ulong num7 = UInt32x32To64((uint)(num5 >> 32), b);
1465 result.Low = (uint)num6;
1466 num7 += num6 >> 32;
1467 result.Mid = (uint)num7;
1468 num7 >>= 32;
1469 result.High = (uint)num7;
1470 }
1471 else
1472 {
1474 }
1475 }
1476 else
1477 {
1478 int num8 = num4;
1479 if (num8 > 14)
1480 {
1481 num8 = 14;
1482 }
1483 if ((byte)num5 == 0 && num8 >= 8)
1484 {
1485 ulong num9 = num5 / 100000000;
1486 if ((uint)num5 == (uint)(num9 * 100000000))
1487 {
1488 num5 = num9;
1489 num4 -= 8;
1490 num8 -= 8;
1491 }
1492 }
1493 if (((int)num5 & 0xF) == 0 && num8 >= 4)
1494 {
1495 ulong num10 = num5 / 10000;
1496 if ((uint)num5 == (uint)(num10 * 10000))
1497 {
1498 num5 = num10;
1499 num4 -= 4;
1500 num8 -= 4;
1501 }
1502 }
1503 if (((int)num5 & 3) == 0 && num8 >= 2)
1504 {
1505 ulong num11 = num5 / 100;
1506 if ((uint)num5 == (uint)(num11 * 100))
1507 {
1508 num5 = num11;
1509 num4 -= 2;
1510 num8 -= 2;
1511 }
1512 }
1513 if (((int)num5 & 1) == 0 && num8 >= 1)
1514 {
1515 ulong num12 = num5 / 10;
1516 if ((uint)num5 == (uint)(num12 * 10))
1517 {
1518 num5 = num12;
1519 num4--;
1520 }
1521 }
1522 num2 |= (uint)(num4 << 16);
1524 }
1526 }
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
static readonly ulong[] s_ulongPowers10
Definition Decimal.cs:207

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

Referenced by System.Decimal.Decimal().