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

◆ TryNumberToDecimal()

static unsafe bool System.Number.TryNumberToDecimal ( ref NumberBuffer number,
ref decimal value )
inlinestaticpackage

Definition at line 5513 of file Number.cs.

5514 {
5515 byte* ptr = number.GetDigitsPointer();
5516 int num = number.Scale;
5517 bool isNegative = number.IsNegative;
5518 uint num2 = *ptr;
5519 if (num2 == 0)
5520 {
5521 value = new decimal(0, 0, 0, isNegative, (byte)Math.Clamp(-num, 0, 28));
5522 return true;
5523 }
5524 if (num > 29)
5525 {
5526 return false;
5527 }
5528 ulong num3 = 0uL;
5529 while (num > -28)
5530 {
5531 num--;
5532 num3 *= 10;
5533 num3 += num2 - 48;
5534 num2 = *(++ptr);
5535 if (num3 >= 1844674407370955161L)
5536 {
5537 break;
5538 }
5539 if (num2 != 0)
5540 {
5541 continue;
5542 }
5543 while (num > 0)
5544 {
5545 num--;
5546 num3 *= 10;
5547 if (num3 >= 1844674407370955161L)
5548 {
5549 break;
5550 }
5551 }
5552 break;
5553 }
5554 uint num4 = 0u;
5555 while ((num > 0 || (num2 != 0 && num > -28)) && (num4 < 429496729 || (num4 == 429496729 && (num3 < 11068046444225730969uL || (num3 == 11068046444225730969uL && num2 <= 53)))))
5556 {
5557 ulong num5 = (ulong)(uint)num3 * 10uL;
5558 ulong num6 = (ulong)((long)(uint)(num3 >> 32) * 10L) + (num5 >> 32);
5559 num3 = (uint)num5 + (num6 << 32);
5560 num4 = (uint)(int)(num6 >> 32) + num4 * 10;
5561 if (num2 != 0)
5562 {
5563 num2 -= 48;
5564 num3 += num2;
5565 if (num3 < num2)
5566 {
5567 num4++;
5568 }
5569 num2 = *(++ptr);
5570 }
5571 num--;
5572 }
5573 if (num2 >= 53)
5574 {
5575 if (num2 == 53 && (num3 & 1) == 0L)
5576 {
5577 num2 = *(++ptr);
5578 bool flag = !number.HasNonZeroTail;
5579 while (num2 != 0 && flag)
5580 {
5581 flag = flag && num2 == 48;
5582 num2 = *(++ptr);
5583 }
5584 if (flag)
5585 {
5586 goto IL_01a8;
5587 }
5588 }
5589 if (++num3 == 0L && ++num4 == 0)
5590 {
5591 num3 = 11068046444225730970uL;
5592 num4 = 429496729u;
5593 num++;
5594 }
5595 }
5596 goto IL_01a8;
5597 IL_01a8:
5598 if (num > 0)
5599 {
5600 return false;
5601 }
5602 if (num <= -29)
5603 {
5604 value = new decimal(0, 0, 0, isNegative, 28);
5605 }
5606 else
5607 {
5608 value = new decimal((int)num3, (int)(num3 >> 32), (int)num4, isNegative, (byte)(-num));
5609 }
5610 return true;
5611 }

References System.Math.Clamp(), System.L, and System.value.

Referenced by System.Buffers.Text.Utf8Parser.TryParse(), and System.Number.TryParseDecimal().