Exemple #1
0
        public void TestPositiveIntegerConstrucor()
        {
            HugeNumber result   = new HugeNumber(12);
            HugeNumber expected = new HugeNumber()
            {
                false, false, true, true, true
            };

            CollectionAssert.AreEqual(expected, result, "Failed on conversion of 12");
            result   = new HugeNumber(11);
            expected = new HugeNumber()
            {
                true, true, true, true, true
            };
            CollectionAssert.AreEqual(expected, result, "Failed on conversion of 11");
            result   = new HugeNumber(13);
            expected = new HugeNumber()
            {
                true, false, true, true, true
            };
            CollectionAssert.AreEqual(expected, result, "Failed on conversion of 13");
            result   = new HugeNumber(15);
            expected = new HugeNumber()
            {
                true, true, false, false, true
            };
            CollectionAssert.AreEqual(expected, result, "Failed on conversion of 15");
        }
Exemple #2
0
    static public HugeNumber operator -(HugeNumber sNumberA, HugeNumber sNumberB)
    {
        HugeNumber sNumberHuge;
        HugeNumber sNumberSmall;
        bool       bIsCompare = CheckIsCompareUnit(sNumberA, sNumberB, out sNumberHuge, out sNumberSmall);

        if (bIsCompare)
        {
            return(new HugeNumber(sNumberA._dNumber - sNumberB._dNumber, sNumberHuge._eUnit));
        }
        else
        {
            bool bIsNegative = sNumberA.p_eUnit < sNumberB.p_eUnit;
            int  iUnitOffset = sNumberHuge._eUnit - sNumberSmall._eUnit;
            for (int i = 0; i < iUnitOffset; i++)
            {
                sNumberSmall._dNumber *= 0.001;
            }

            HugeNumber sReturnNumber = new HugeNumber(sNumberHuge._dNumber - sNumberSmall._dNumber, sNumberHuge._eUnit);
            if (bIsNegative)
            {
                sReturnNumber._dNumber *= -1;
            }

            return(sReturnNumber);
        }
    }
Exemple #3
0
        public void TestAdd()
        {
            HugeNumber eleven = new HugeNumber()
            {
                true, true, true, true, true
            };
            HugeNumber twelve = new HugeNumber()
            {
                false, false, true, true, true
            };
            HugeNumber thirteen = new HugeNumber()
            {
                true, false, true, true, true
            };
            HugeNumber twentythree = new HugeNumber {
                true, true, false, true, false, true, true
            };
            HugeNumber minus_twentythree = twentythree.Negate();

            CollectionAssert.AreEqual(twentythree, eleven + twelve, "Add failed 11+12.");
            CollectionAssert.AreEqual(twentythree, twelve + eleven, "Add failed 12+11.");
            CollectionAssert.AreEqual(new HugeNumber()
            {
                true
            }, twelve + eleven.Negate(), "Add failed 12+-11.");
            CollectionAssert.AreEqual(new HugeNumber()
            {
            }, twentythree + minus_twentythree, "Add failed 23+-23.");
        }
Exemple #4
0
        public void TestSubtract()
        {
            HugeNumber eleven = new HugeNumber()
            {
                true, true, true, true, true
            };
            HugeNumber twelve = new HugeNumber()
            {
                false, false, true, true, true
            };
            HugeNumber thirteen = new HugeNumber()
            {
                true, false, true, true, true
            };
            HugeNumber one = new HugeNumber {
                true
            };

            CollectionAssert.AreEqual(one.Negate(), eleven - twelve, "Add failed 11-12.");
            CollectionAssert.AreEqual(one, twelve - eleven, "Add failed 12-11.");
            HugeNumber twentythree = new HugeNumber {
                true, true, false, true, false, true, true
            };

            CollectionAssert.AreEqual(twentythree, twelve - eleven.Negate(), "Add failed 12--11.");
        }
Exemple #5
0
        private void TestCase_Operator_1()
        {
            Debug.Log("Start TestCase_Operator_1");

            HugeNumber sHugeNum1 = new HugeNumber(123, HugeNumber.EUnit.None);
            HugeNumber sHugeNum2 = new HugeNumber(456, HugeNumber.EUnit.None);

            Debug.Log(sHugeNum1 + sHugeNum2);
            Debug.Log(sHugeNum1 + sHugeNum2 - sHugeNum1);

            sHugeNum1 = new HugeNumber(100, HugeNumber.EUnit.A);
            sHugeNum2 = new HugeNumber(100, HugeNumber.EUnit.B);
            Debug.Log(sHugeNum1 + sHugeNum2);
            Debug.Log(sHugeNum1 + sHugeNum2 - sHugeNum1);

            //CManagerProfiler.instance.DoStartTestCase( "Test" );
            sHugeNum1 = new HugeNumber(1, HugeNumber.EUnit.A);
            sHugeNum2 = new HugeNumber(1, HugeNumber.EUnit.C);
            HugeNumber sHugeNum3 = sHugeNum2;

            for (int i = 0; i < 1000; i++)
            {
                sHugeNum3 += sHugeNum1;
            }

            sHugeNum3 += new HugeNumber(999, HugeNumber.EUnit.B);
            //CManagerProfiler.instance.DoFinishTestCase( "Test" );
            //CManagerProfiler.instance.DoPrintResult(false);

            Debug.Log(sHugeNum3);
        }
        public void HugeNumber_ToStringTest()
        {
            int    iValue          = 1000;
            string striValueString = "1A";

            HugeNumber sHugeNumber = new HugeNumber(iValue);

            Assert.IsTrue(sHugeNumber.ToString() == striValueString);
        }
    public void AddNumber(HugeNumber number)
    {
        string finalNumberValue = "";
        int    numberIterator   = numberValue.Length - 1;

        // when sum of 2 chars is bigger than 10 then add 1 in next iteration
        bool addOneNext = false;

        for (int i = number.numberValue.Length - 1; i >= 0; i--)
        {
            int num = number.numberValue[i] - '0';
            // when current number is lower than other then insert rest from other on front
            if (numberIterator < 0)
            {
                if (addOneNext)
                {
                    num++;
                    addOneNext = false;
                }
                finalNumberValue = finalNumberValue.Insert(0, num.ToString());
                continue;
            }

            int current = numberValue[numberIterator] - '0';
            int final   = num + current;

            // if previous sum was >10 then add 1
            if (addOneNext)
            {
                final++;
                addOneNext = false;
            }

            string finalString = final.ToString();

            // if sum is >=10 then remove 1 to add to next iteration
            if (final >= 10)
            {
                addOneNext  = true;
                finalString = finalString.Substring(1);
            }

            numberIterator--;
            finalNumberValue = finalNumberValue.Insert(0, finalString);
        }
        // if other number is lower than current then add what's left from current number
        if (numberIterator >= 0)
        {
            finalNumberValue = finalNumberValue.Insert(0, numberValue.Substring(0, numberIterator + 1));
        }
        else if (addOneNext)
        {
            finalNumberValue = finalNumberValue.Insert(0, "1");
        }
        numberValue = finalNumberValue;
    }
Exemple #8
0
 /// <summary>
 /// Calculates the approximate area of a point on a map projection with the given
 /// characteristics, by transforming the point and its nearest neighbors to latitude and
 /// longitude, calculating the midpoints between them, and calculating the area of the
 /// region enclosed within those midpoints.
 /// </summary>
 /// <param name="radius">The radius of the planet.</param>
 /// <param name="x">The x coordinate of a point on a map projection, with zero as the
 /// westernmost point.</param>
 /// <param name="y">The y coordinate of a point on a map projection, with zero as the
 /// northernmost point.</param>
 /// <param name="resolution">The vertical resolution of the projection.</param>
 /// <param name="options">
 /// The map projection options used to generate the map used.
 /// </param>
 /// <returns>The area of the given point, in m².</returns>
 public static HugeNumber GetAreaOfPoint(
     HugeNumber radius,
     int x, int y,
     int resolution,
     MapProjectionOptions options) => GetAreaOfPointFromRadiusSquared(
     radius.Square(),
     x, y,
     (int)Math.Floor(resolution * options.AspectRatio),
     resolution,
     options);
Exemple #9
0
        public void TestCopyConstructor()
        {
            HugeNumber original = new HugeNumber()
            {
                true, false, true, false, true, true
            };
            HugeNumber copy = new HugeNumber(original);

            CollectionAssert.AreEqual(original, copy, "Copy constructor failed.");
        }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of <see cref="StarSystemChildDefinition"/>.
 /// </summary>
 /// <param name="density">The density of this type of child within the containing parent
 /// region.</param>
 /// <param name="spectralClass">The <see cref="Stars.SpectralClass"/> of the
 /// primary star of the star system.</param>
 /// <param name="luminosityClass">
 /// The <see cref="Stars.LuminosityClass"/> of the primary star of the star
 /// system.
 /// </param>
 /// <param name="populationII">True if the primary star of the star system is to be a
 /// Population II star.</param>
 /// <param name="allowBinary">
 /// Whether a multiple-star system will satisfy this definition.
 /// </param>
 public StarSystemChildDefinition(
     HugeNumber density,
     SpectralClass?spectralClass     = null,
     LuminosityClass?luminosityClass = null,
     bool populationII = false,
     bool allowBinary  = true) : base(StarSystem._StarSystemSpace, density)
 {
     StarType        = StarType.MainSequence;
     SpectralClass   = spectralClass;
     LuminosityClass = luminosityClass;
     PopulationII    = populationII;
     AllowBinary     = allowBinary;
 }
    public void SubtractNumber(HugeNumber number)
    {
        string finalNumberValue = "";

        int lengthDifference = numberValue.Length - number.numberValue.Length;

        // Initially take carry zero
        int carry = 0;

        // Traverse from end of both strings
        for (int i = number.numberValue.Length - 1; i >= 0; i--)
        {
            // Do school mathematics, compute
            // difference of current digits and carry
            int subtraction = ((numberValue[i + lengthDifference] - '0') - (number.numberValue[i] - '0') - carry);
            if (subtraction < 0)
            {
                subtraction = subtraction + 10;
                carry       = 1;
            }
            else
            {
                carry = 0;
            }

            finalNumberValue += subtraction.ToString();
        }

        // subtract remaining digits of numberValue[]
        for (int i = lengthDifference - 1; i >= 0; i--)
        {
            if (numberValue[i] == '0' && carry > 0)
            {
                finalNumberValue += "9";
                continue;
            }
            int subtraction = ((numberValue[i] - '0') - carry);

            // remove preceding 0's
            if (i > 0 || subtraction > 0)
            {
                finalNumberValue += subtraction.ToString();
            }
            carry = 0;
        }

        // reverse resultant string
        char[] reveerseResultArray = finalNumberValue.ToCharArray();
        Array.Reverse(reveerseResultArray);
        numberValue = new string(reveerseResultArray);
    }
Exemple #12
0
        public void TestNegate()
        {
            HugeNumber input = new HugeNumber()
            {
                true, true, false, false, true
            };                                                                                  // 15
            HugeNumber expected = new HugeNumber()
            {
                true, false, false, false, true, true
            };                                                                                            // -15
            HugeNumber result = input.Negate();

            CollectionAssert.AreEqual(expected, result, "Failed on negate of 15.");
            CollectionAssert.AreEqual(input, result.Negate(), "Failed on negate of -15.");
        }
Exemple #13
0
        public void TestToString()
        {
            HugeNumber result = new HugeNumber()
            {
                true, true, false, false, true
            };
            string expected = "11001";

            Assert.AreEqual(expected, result.ToString(), "ToString failed for 15.");
            result = new HugeNumber()
            {
                true, false, true, false, true, true
            };
            expected = "101011";
            Assert.AreEqual(expected, result.ToString(), "ToString failed for -11.");
        }
Exemple #14
0
        public void TestNegativeIntegerConstrucor()
        {
            HugeNumber result   = new HugeNumber(-12);
            HugeNumber expected = new HugeNumber()
            {
                false, false, true, false, true, true
            };

            CollectionAssert.AreEqual(expected, result, "Failed on conversion of -12.");
            result   = new HugeNumber(-11);
            expected = new HugeNumber()
            {
                true, false, true, false, true, true
            };
            CollectionAssert.AreEqual(expected, result, "Failed on conversion of -11.");
        }
Exemple #15
0
        public void TestToInt()
        {
            HugeNumber result = new HugeNumber()
            {
                true, true, false, false, true
            };
            long expected = 15;

            Assert.AreEqual(expected, result.ToLong(), "ToLong failed for 15.");
            result = new HugeNumber()
            {
                true, false, true, false, true, true
            };
            expected = -11;
            Assert.AreEqual(expected, result.ToLong(), "ToLong failed for 15.");
        }
Exemple #16
0
        public void TestCompare()
        {
            HugeNumber eleven = new HugeNumber()
            {
                true, true, true, true, true
            };
            HugeNumber twelve = new HugeNumber()
            {
                false, false, true, true, true
            };
            HugeNumber thirteen = new HugeNumber()
            {
                true, false, true, true, true
            };

            Assert.AreEqual(1, twelve.CompareTo(eleven), "Compare 12 > 11 failed.");
            Assert.AreEqual(0, twelve.CompareTo(twelve), "Compare 12 == 12 failed.");
            Assert.AreEqual(-1, twelve.CompareTo(thirteen), "Compare 12 < 13 failed.");
            HugeNumber sixtyfour = new HugeNumber()
            {
                false, false, false, false, false, false, true
            };

            Assert.AreEqual(-1, twelve.CompareTo(sixtyfour), "Compare 12 < 64 failed.");
            HugeNumber five = new HugeNumber()
            {
                true, false, true
            };

            Assert.AreEqual(1, twelve.CompareTo(five), "Compare 12 > 5 failed.");
            HugeNumber minus_fifteen = new HugeNumber()
            {
                true, false, false, false, true, true
            };                                                                                                 // -15

            Assert.AreEqual(1, twelve.CompareTo(minus_fifteen), "Compare 12 > -15 failed.");
            Assert.AreEqual(-1, minus_fifteen.CompareTo(twelve), "Compare -15 < 12 failed.");
            Assert.IsTrue(twelve > eleven, "Compare 12 > 11 failed.");
            Assert.IsFalse(eleven > twelve, "Compare 11 < 12 failed.");
            Assert.IsFalse(twelve < eleven, "Compare 12 > 11 failed.");
            Assert.IsTrue(eleven < twelve, "Compare 11 < 12 failed.");
            Assert.IsTrue(twelve == twelve, "Compare 12 == 12 failed.");
            Assert.IsTrue(twelve <= twelve, "Compare 12 <= 12 failed.");
            Assert.IsFalse(twelve <= eleven, "Compare 12 <= 11 failed.");
            Assert.IsTrue(twelve >= twelve, "Compare 12 <= 12 failed.");
            Assert.IsTrue(twelve >= eleven, "Compare 12 <= 11 failed.");
        }
Exemple #17
0
        private void TestCase_Operator_2()
        {
            Debug.Log("Start TestCase_Operator_2");

            SCManagerProfiler.DoStartTestCase("Test");
            for (int i = 0; i < 1000; i++)
            {
                HugeNumber sHugeNum1 = new HugeNumber(1, HugeNumber.EUnit.None);
                HugeNumber sHugeNum2 = sHugeNum1 * 100000000;
                HugeNumber sHugeNum3 = new HugeNumber(1, HugeNumber.EUnit.G);

                sHugeNum3 += sHugeNum2;
                sHugeNum3 -= sHugeNum2;
            }
            SCManagerProfiler.DoFinishTestCase("Test");
            SCManagerProfiler.DoPrintResult(false);
        }
Exemple #18
0
        private void TestCase_InitNumber()
        {
            Debug.Log("Start TestCase_InitNumber");

            HugeNumber sHugeNum = new HugeNumber(100, HugeNumber.EUnit.None);

            Debug.Log(sHugeNum);

            sHugeNum = new HugeNumber(1234100.1234, HugeNumber.EUnit.None);
            Debug.Log(sHugeNum);

            sHugeNum = new HugeNumber(0.1234567, HugeNumber.EUnit.A);
            Debug.Log(sHugeNum);

            sHugeNum = new HugeNumber(1234100.1234, HugeNumber.EUnit.G);
            Debug.Log(sHugeNum);
        }
    static void Main()
    {
        // Write a program to calculate n! for each n in the range [1..100].
        // Implement first a method that multiplies a number represented as array of digits by given integer number.
        
        int n = 100;
        // We will use the class HugeNumber we created in Problem 8
        HugeNumber factorial = new HugeNumber(new byte[] { 1 });
        for (int i = 1; i <= n; i++)
        {
            factorial = factorial * i;
            Console.WriteLine("{0}! = {1}", i, factorial);

            if (i != n)
            {
                Console.Write("Press any key to see the next factorial...");
                Console.ReadKey(true);
                Console.Clear();
            }
        }
    }
    public bool CanSubtract(HugeNumber number)
    {
        int numberLength = number.numberValue.Length;

        if (numberValue.Length < numberLength)
        {
            return(false);
        }
        if (numberValue.Length > numberLength)
        {
            return(true);
        }

        for (int i = 0; i < numberValue.Length; i++)
        {
            if (numberValue[i] < number.numberValue[i])
            {
                return(false);
            }
        }
        return(true);
    }
Exemple #21
0
        public void TestAddPerformance()
        {
            Random rnd = new Random(23);

            for (int i = 0; i < 100; ++i)
            {
                int        a = rnd.Next(short.MaxValue);
                int        b = rnd.Next() * rnd.Next(short.MaxValue);
                HugeNumber x = new HugeNumber(a);
                HugeNumber y = new HugeNumber(b);
                HugeNumber z = x + y;
                Assert.AreEqual(a + b, z.ToLong(), "Addition failed.");
                Assert.AreEqual(a + b, (y + x).ToLong(), "Addition failed.");
            }
            for (int i = 0; i < 100; ++i)
            {                     // big numbers
                long       a = rnd.Next(short.MaxValue) * int.MaxValue;
                long       b = rnd.Next(short.MaxValue) * rnd.Next(short.MaxValue) * int.MaxValue;
                HugeNumber x = new HugeNumber(a);
                HugeNumber y = new HugeNumber(b);
                HugeNumber z = x + y;
                Assert.AreEqual(0, (z).ToLong() - (a + b), "Addition failed.");
            }
            for (int i = 0; i < 1000; ++i)
            {
                int        a = -rnd.Next(short.MaxValue);           // test with negatives
                int        b = rnd.Next(short.MaxValue) * rnd.Next(short.MaxValue);
                HugeNumber x = new HugeNumber(a);
                HugeNumber y = new HugeNumber(b);
                HugeNumber z = x + y;
                Assert.AreEqual(a + b, z.ToLong(), "Addition failed.");
                Assert.AreEqual(a + b, (y + x).ToLong(), "Addition failed.");
            }
            int        v = rnd.Next(short.MaxValue);
            HugeNumber V = new HugeNumber(v);

            Assert.AreEqual(0, (V + V.Negate()).ToLong(), "Addition to 0 failed.");
        }
Exemple #22
0
 public OrbitalParameters(
     HugeNumber orbitedMass,
     Vector3 <HugeNumber> orbitedPosition,
     HugeNumber periapsis,
     double eccentricity,
     double inclination,
     double angleAscending,
     double argumentOfPeriapsis,
     double trueAnomaly,
     bool circular         = false,
     bool fromEccentricity = false)
 {
     Circular            = circular;
     FromEccentricity    = fromEccentricity;
     OrbitedMass         = orbitedMass;
     OrbitedPosition     = orbitedPosition;
     Periapsis           = periapsis;
     Eccentricity        = eccentricity;
     Inclination         = inclination;
     AngleAscending      = angleAscending;
     ArgumentOfPeriapsis = argumentOfPeriapsis;
     TrueAnomaly         = trueAnomaly;
 }
Exemple #23
0
    static public bool CheckIsCompareUnit(HugeNumber sNumberA, HugeNumber sNumberB, out HugeNumber sNumberHuge, out HugeNumber sNumberSmall)
    {
        bool bIsCompare = true;

        if (sNumberA._eUnit > sNumberB._eUnit)
        {
            sNumberHuge  = sNumberA;
            sNumberSmall = sNumberB;
            bIsCompare   = false;
        }
        else if (sNumberA._eUnit < sNumberB._eUnit)
        {
            sNumberHuge  = sNumberB;
            sNumberSmall = sNumberA;
            bIsCompare   = false;
        }

        else if (sNumberA._dNumber > sNumberB._dNumber)
        {
            sNumberHuge  = sNumberA;
            sNumberSmall = sNumberB;
            bIsCompare   = true;
        }
        else if (sNumberA._dNumber < sNumberB._dNumber)
        {
            sNumberHuge  = sNumberB;
            sNumberSmall = sNumberA;
            bIsCompare   = true;
        }
        else
        {
            sNumberHuge  = new HugeNumber();
            sNumberSmall = new HugeNumber();
        }

        return(bIsCompare);
    }
Exemple #24
0
 /// <summary>
 /// Initializes a new instance of <see cref="PlanetChildDefinition"/>.
 /// </summary>
 /// <param name="density">
 /// The density of this type of child within the containing parent region.
 /// </param>
 /// <param name="planemoType">
 /// The type of <see cref="Planetoid"/>.
 /// </param>
 public PlanetChildDefinition(HugeNumber density, PlanetType planemoType = PlanetType.Dwarf) : base(Planetoid.GetSpaceForType(planemoType), density) => PlanetType = planemoType;
Exemple #25
0
 public PlanetaryRing(bool icy, HugeNumber innerRadius, HugeNumber outerRadius)
 {
     Icy         = icy;
     InnerRadius = innerRadius;
     OuterRadius = outerRadius;
 }
Exemple #26
0
 /// <summary>
 /// Gets an <see cref="OrbitalParameters"/> instance which defines a circular orbit.
 /// </summary>
 /// <param name="orbitedMass">
 /// The mass of the object or system being orbited, in kg.
 /// </param>
 /// <param name="orbitedPosition">
 /// The position of the object or system being orbited at the epoch, as a vector in the same
 /// reference frame as the orbiting object.
 /// </param>
 public static OrbitalParameters GetCircular(HugeNumber orbitedMass, Vector3 <HugeNumber> orbitedPosition)
 => new(
    static void Test()
    {        
        HugeNumber a, b, c;
        Random rand = new Random();
        while (true)
        {
            Console.ReadKey(true);
            long num1 = rand.Next(1000);
            long num2 = rand.Next(20);
            long sum = num1 + num2;            

            a = new HugeNumber(num1.ToString());
            b = new HugeNumber(num2.ToString());
            c = a + b;
            Console.WriteLine("{0} + {1} = {2}", a, b, c);

            long result = long.Parse(c.ToString());
            if (result != sum)
            {
                Console.Write("Wrong! This is the correct result: ");
                Console.WriteLine("{0} + {1} = {2}", num1, num2, sum);
            }
        }
    }
    static void Main()
    {
        Console.WriteLine("Enter some big positive integers:");

        Console.Write("a = ");
        HugeNumber a = new HugeNumber(Console.ReadLine());

        Console.Write("b = ");
        HugeNumber b = new HugeNumber(Console.ReadLine());

        HugeNumber c = a + b;
        Console.WriteLine("{0} + {1} = {2}", a, b, c);

        Console.WriteLine("\nWorks with arrays as well:");
        a = new HugeNumber(new byte[] { 3, 2, 1 });
        b = new HugeNumber(new byte[] { 6, 5, 4 });
        Console.WriteLine("{0} + {1} = {2}", a, b, a + b);

        //Test();
    }
Exemple #29
0
 /// <summary>
 /// Initializes a new instance of <see cref="StarSystemChildDefinition"/>.
 /// </summary>
 /// <param name="density">The density of this type of child within the containing parent
 /// region.</param>
 public StarSystemChildDefinition(HugeNumber density) : base(StarSystem._StarSystemSpace, density)
 {
 }
 // Multiplication (int * HugeNumber)
 public static HugeNumber operator *(int small, HugeNumber big)
 {
     HugeNumber result = new HugeNumber(new byte[] { 0 });
     for (int i = 0; i < small; i++)
     {
         result = result + big;
     }
     return result;
 }
    public void MultiplyByNumber(HugeNumber number)
    {
        string finalNumberValue = "";

        if (numberValue.Length == 0 || number.numberValue.Length == 0 ||
            numberValue == "0" || number.numberValue == "0")
        {
            numberValue = "0";
            return;
        }

        // will keep the result number in vector
        // in reverse order
        int[] resultReversed = new int[numberValue.Length + number.numberValue.Length];

        // Below two indexes are used to
        // find positions in result.
        int indexN1 = 0;
        int i;

        // Go from right to left in num1
        for (i = numberValue.Length - 1; i >= 0; i--)
        {
            int carry = 0;
            int n1    = numberValue[i] - '0';

            // To shift position to left after every
            // multipliccharAtion of a digit in num2
            int indexN2 = 0;

            // Go from right to left in num2
            for (int j = number.numberValue.Length - 1; j >= 0; j--)
            {
                // Take current digit of second number
                int n2 = number.numberValue[j] - '0';

                // Multiply with current digit of first number
                // and add result to previously stored result
                // charAt current position.
                int sum = n1 * n2 + resultReversed[indexN1 + indexN2] + carry;

                // Carry for next itercharAtion
                carry = sum / 10;

                // Store result
                resultReversed[indexN1 + indexN2] = sum % 10;

                indexN2++;
            }

            // store carry in next cell
            if (carry > 0)
            {
                resultReversed[indexN1 + indexN2] += carry;
            }

            // To shift position to left after every
            // multipliccharAtion of a digit in num1.
            indexN1++;
        }

        // ignore '0's from the right
        i = resultReversed.Length - 1;
        while (i >= 0 && resultReversed[i] == 0)
        {
            i--;
        }

        // If all were '0's - means either both
        // or one of num1 or num2 were '0'
        if (i == -1)
        {
            numberValue = "0";
            return;
        }

        while (i >= 0)
        {
            finalNumberValue += (resultReversed[i--]);
        }

        numberValue = finalNumberValue;
    }
Exemple #32
0
 /// <summary>
 /// Initializes a new instance of <see cref="SurfaceRegion"/>.
 /// </summary>
 /// <param name="planet">The planet on which this region is found.</param>
 /// <param name="position">The normalized position vector of this region.</param>
 /// <param name="latitudeRange">
 /// <para>
 /// The range of latitudes encompassed by this region, as an angle (in radians).
 /// </para>
 /// <para>
 /// Maximum value is π (a full hemisphere, which produces the full globe).
 /// </para>
 /// </param>
 public SurfaceRegion(Planetoid planet, Vector3 <HugeNumber> position, HugeNumber latitudeRange)
     : base(planet.Id, new Frustum <HugeNumber>(2, position * (planet.Shape.ContainingRadius + planet.Atmosphere.AtmosphericHeight), HugeNumber.Min(latitudeRange, HugeNumber.Pi), 0))
 {
 }
Exemple #33
0
 /// <summary>
 /// Initializes a new instance of <see cref="ChildDefinition"/>.
 /// </summary>
 /// <param name="space">The radius of the open space required for this child type.</param>
 /// <param name="density">
 /// The density of this type of child within the containing parent region.
 /// </param>
 /// <param name="structureType">The type of this child.</param>
 public ChildDefinition(HugeNumber space, HugeNumber density, CosmicStructureType structureType)
 {
     Density       = density;
     Space         = space;
     StructureType = structureType;
 }
Exemple #34
0
 /// <summary>
 /// Initializes a new instance of <see cref="SurfaceRegion"/>.
 /// </summary>
 /// <param name="planet">The planet on which this region is found.</param>
 /// <param name="latitude">The latitude of the center of the region.</param>
 /// <param name="longitude">The longitude of the center of the region.</param>
 /// <param name="latitudeRange">
 /// <para>
 /// The range of latitudes encompassed by this region, as an angle (in radians).
 /// </para>
 /// <para>
 /// Maximum value is π (a full hemisphere, which produces the full globe).
 /// </para>
 /// </param>
 public SurfaceRegion(Planetoid planet, double latitude, double longitude, HugeNumber latitudeRange)
     : base(planet.Id, new Frustum <HugeNumber>(2, planet.LatitudeAndLongitudeToVector(latitude, longitude) * (planet.Shape.ContainingRadius + planet.Atmosphere.AtmosphericHeight), HugeNumber.Min(latitudeRange, HugeNumber.Pi), 0))
 {
 }