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

◆ DblToRgbPrecise()

static void System.Xml.Xsl.XPathConvert.BigNumber.DblToRgbPrecise ( double dbl,
byte[] mantissa,
out int exponent,
out int mantissaSize )
inlinestatic

Definition at line 708 of file XPathConvert.cs.

709 {
715 uint num = DblHi(dbl);
716 uint num2 = DblLo(dbl);
717 bigInteger2.InitFromDigits(1u, 0u, 1);
718 bigInteger3.InitFromDigits(1u, 0u, 1);
719 int num3 = (int)(((num & 0x7FF00000) >> 20) - 1075);
720 uint num4 = num & 0xFFFFFu;
721 uint num5 = num2;
722 int num6 = 2;
723 bool flag = false;
724 double num7;
725 int num8;
726 if (num3 == -1075)
727 {
728 if (num4 == 0)
729 {
730 num6 = 1;
731 }
732 num7 = BitConverter.Int64BitsToDouble(5760103923406864384L);
733 num7 *= dbl;
734 num8 = (int)(((DblHi(num7) & 0x7FF00000) >> 20) - 1279);
735 num = DblHi(num7);
736 num &= 0xFFFFFu;
737 num |= 0x3FF00000u;
738 num7 = BitConverter.UInt64BitsToDouble(((ulong)num << 32) | DblLo(num7));
739 num3++;
740 }
741 else
742 {
743 num &= 0xFFFFFu;
744 num |= 0x3FF00000u;
745 num7 = BitConverter.UInt64BitsToDouble(((ulong)num << 32) | num2);
746 num8 = num3 + 52;
747 if (num5 == 0 && num4 == 0 && num3 > -1074)
748 {
749 num4 = 2097152u;
750 num3--;
751 flag = true;
752 }
753 else
754 {
755 num4 |= 0x100000u;
756 }
757 }
758 num7 = (num7 - 1.5) * 0.289529654602168 + 0.1760912590558 + (double)num8 * 0.301029995663981;
759 int num9 = (int)num7;
760 if (num7 < 0.0 && num7 != (double)num9)
761 {
762 num9--;
763 }
764 int num10;
765 int num11;
766 if (num3 >= 0)
767 {
768 num10 = num3;
769 num11 = 0;
770 }
771 else
772 {
773 num10 = 0;
774 num11 = -num3;
775 }
776 int num12;
777 int num13;
778 if (num9 >= 0)
779 {
780 num12 = 0;
781 num13 = num9;
782 num11 += num9;
783 }
784 else
785 {
786 num10 -= num9;
787 num12 = -num9;
788 num13 = 0;
789 }
790 if (num10 > 0 && num11 > 0)
791 {
792 num8 = ((num10 < num11) ? num10 : num11);
793 num10 -= num8;
794 num11 -= num8;
795 }
796 num10++;
797 num11++;
798 if (num12 > 0)
799 {
800 bigInteger3.MulPow5(num12);
801 bigInteger.InitFromBigint(bigInteger3);
802 if (1 == num6)
803 {
804 bigInteger.MulAdd(num5, 0u);
805 }
806 else
807 {
808 bigInteger.MulAdd(num4, 0u);
809 bigInteger.ShiftLeft(32);
810 if (num5 != 0)
811 {
812 bigInteger5.InitFromBigint(bigInteger3);
813 bigInteger5.MulAdd(num5, 0u);
815 }
816 }
817 }
818 else
819 {
820 bigInteger.InitFromDigits(num5, num4, num6);
821 if (num13 > 0)
822 {
823 bigInteger2.MulPow5(num13);
824 }
825 }
827 num8 = (num8 + 28 - num11) & 0x1F;
828 num10 += num8;
829 num11 += num8;
830 bigInteger.ShiftLeft(num10);
831 if (num10 > 1)
832 {
833 bigInteger3.ShiftLeft(num10 - 1);
834 }
835 bigInteger2.ShiftLeft(num11);
837 if (flag)
838 {
840 bigInteger6.InitFromBigint(bigInteger3);
841 bigInteger3.ShiftLeft(1);
842 }
843 else
844 {
846 }
847 int num14 = 0;
848 while (true)
849 {
850 byte b = (byte)bigInteger.DivRem(bigInteger2);
851 if (num14 == 0 && b == 0)
852 {
853 num9--;
854 goto IL_03c7;
855 }
856 num8 = bigInteger.CompareTo(bigInteger6);
857 int num15;
858 if (bigInteger2.CompareTo(bigInteger3) < 0)
859 {
860 num15 = 1;
861 }
862 else
863 {
864 bigInteger5.InitFromBigint(bigInteger2);
865 bigInteger5.Subtract(bigInteger3);
866 num15 = bigInteger.CompareTo(bigInteger5);
867 }
868 if (num15 == 0 && (num2 & 1) == 0)
869 {
870 if (b != 9)
871 {
872 if (num8 > 0)
873 {
874 b++;
875 }
876 mantissa[num14++] = b;
877 break;
878 }
879 }
880 else
881 {
882 if (num8 < 0 || (num8 == 0 && (num2 & 1) == 0))
883 {
884 if (num15 > 0)
885 {
886 bigInteger.ShiftLeft(1);
887 num15 = bigInteger.CompareTo(bigInteger2);
888 if ((num15 > 0 || (num15 == 0 && ((uint)b & (true ? 1u : 0u)) != 0)) && b++ == 9)
889 {
890 goto IL_0412;
891 }
892 }
893 mantissa[num14++] = b;
894 break;
895 }
896 if (num15 <= 0)
897 {
898 mantissa[num14++] = b;
899 goto IL_03c7;
900 }
901 if (b != 9)
902 {
903 mantissa[num14++] = (byte)(b + 1);
904 break;
905 }
906 }
907 goto IL_0412;
908 IL_0412:
909 while (true)
910 {
911 if (num14 > 0)
912 {
913 if (mantissa[--num14] != 9)
914 {
915 mantissa[num14++]++;
916 break;
917 }
918 continue;
919 }
920 num9++;
921 mantissa[num14++] = 1;
922 break;
923 }
924 break;
925 IL_03c7:
926 bigInteger.MulAdd(10u, 0u);
927 bigInteger3.MulAdd(10u, 0u);
929 {
930 bigInteger6.MulAdd(10u, 0u);
931 }
932 }
933 exponent = num9 + 1;
935 }
static int CbitZeroLeft(uint u)
static uint DblLo(double dbl)
static uint DblHi(double dbl)

References System.Xml.Xsl.XPathConvert.CbitZeroLeft(), System.Xml.Xsl.XPathConvert.DblHi(), System.Xml.Xsl.XPathConvert.DblLo(), System.Xml.Dictionary, System.Xml.Xsl.XPathConvert.BigInteger.InitFromBigint(), System.BitConverter.Int64BitsToDouble(), System.Xml.L, and System.BitConverter.UInt64BitsToDouble().

Referenced by System.Xml.Xsl.XPathConvert.FloatingDecimal.InitFromDouble().