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

◆ TryDigitGenCounted()

static bool System.Number.Grisu3.TryDigitGenCounted ( in DiyFp w,
int requestedDigits,
Span< byte > buffer,
out int length,
out int kappa )
inlinestaticprivate

Definition at line 963 of file Number.cs.

964 {
965 ulong num = 1uL;
966 DiyFp diyFp = new DiyFp((ulong)(1L << -w.e), w.e);
967 uint num2 = (uint)(w.f >> -diyFp.e);
968 ulong num3 = w.f & (diyFp.f - 1);
969 if (num3 == 0L && (requestedDigits >= 11 || num2 < s_SmallPowersOfTen[requestedDigits - 1]))
970 {
971 length = 0;
972 kappa = 0;
973 return false;
974 }
975 uint num4 = BiggestPowerTen(num2, 64 - -diyFp.e, out kappa);
976 length = 0;
977 while (kappa > 0)
978 {
979 uint num5;
980 (num5, num2) = Math.DivRem(num2, num4);
981 buffer[length] = (byte)(48 + num5);
982 length++;
983 requestedDigits--;
984 kappa--;
985 if (requestedDigits == 0)
986 {
987 break;
988 }
989 num4 /= 10;
990 }
991 if (requestedDigits == 0)
992 {
993 ulong rest = ((ulong)num2 << -diyFp.e) + num3;
994 return TryRoundWeedCounted(buffer, length, rest, (ulong)num4 << -diyFp.e, num, ref kappa);
995 }
996 while (requestedDigits > 0 && num3 > num)
997 {
998 num3 *= 10;
999 num *= 10;
1000 uint num6 = (uint)(num3 >> -diyFp.e);
1001 buffer[length] = (byte)(48 + num6);
1002 length++;
1003 requestedDigits--;
1004 kappa--;
1005 num3 &= diyFp.f - 1;
1006 }
1007 if (requestedDigits != 0)
1008 {
1009 buffer[0] = 0;
1010 length = 0;
1011 kappa = 0;
1012 return false;
1013 }
1014 return TryRoundWeedCounted(buffer, length, num3, diyFp.f, num, ref kappa);
1015 }
static readonly uint[] s_SmallPowersOfTen
Definition Number.cs:836
static bool TryRoundWeedCounted(Span< byte > buffer, int length, ulong rest, ulong tenKappa, ulong unit, ref int kappa)
Definition Number.cs:1065
static uint BiggestPowerTen(uint number, int numberBits, out int exponentPlusOne)
Definition Number.cs:950

References System.Number.Grisu3.BiggestPowerTen(), System.buffer, System.Math.DivRem(), System.Number.DiyFp.e, System.Number.DiyFp.f, System.L, System.length, System.Number.Grisu3.s_SmallPowersOfTen, and System.Number.Grisu3.TryRoundWeedCounted().

Referenced by System.Number.Grisu3.TryRunCounted().