Beispiel #1
0
        static public string ToDigitString(double d, int digitBase)
        {
            // ensure the base is valid
            if (!(digitBase >= 2))
            {
                throw new ArgumentOutOfRangeException("digitBase", digitBase,
                                                      "digitBase must be greater or equal to 2.");
            }

            StringBuilder digitString = new StringBuilder();

            if (d < 0)
            {
                digitString.Append('-');
            }

            double dRemainder = Math.Abs(d);
            int    digitPlace = (int)Math.Floor(Math.Log(dRemainder, digitBase));

            while (digitPlace >= 0 || d > 0)
            {
                if (digitPlace == -1)
                {
                    digitString.Append('.');
                }

                double digitMultiplier = Math.Pow(digitBase, digitPlace);
                int    digitIndex      = (int)Math.Floor(dRemainder / digitMultiplier);
                dRemainder -= (digitIndex * digitMultiplier);

                digitString.Append(Math2.ToDigit(digitIndex, digitBase));

                Debug.Assert(d < digitIndex);

                digitPlace--;
            }

            return(digitString.ToString());
        }
Beispiel #2
0
 static public string RadianToString(double radians, int significantDigits)
 {
     return(Math2.ToString(ToUnitRadian(radians) / Math2.PI, significantDigits) + " " + ((char)0x03C0));
 }
Beispiel #3
0
        //===============================================================================

        static public string RadianToString(double radians)
        {
            return((Math2.ToUnitRadian(radians) / Math2.PI).ToString() + " " + ((char)0x03C0));
        }
Beispiel #4
0
 static public bool      IsPowerOf2(int x)
 {
     return(x == Math2.Pow2(Math2.Log2(x)));
 }
Beispiel #5
0
 static public float             CeilingToBase(float a, int b)
 {
     return((float)Math2.CeilingToBase((double)a, b));
 }
Beispiel #6
0
 static public int               CeilingToBase(int a, int b)
 {
     return((int)Math2.CeilingToBase((double)a, b));
 }
Beispiel #7
0
 static public float             FloorToBase(float a, int b)
 {
     return((float)Math2.FloorToBase((double)a, b));
 }
Beispiel #8
0
 static public int               FloorToBase(int a, int b)
 {
     return((int)Math2.FloorToBase((double)a, b));
 }
Beispiel #9
0
 static public float             RoundToBase(float a, int b)
 {
     return((float)Math2.RoundToBase((double)a, b));
 }
Beispiel #10
0
        //===============================================================================

        static public int               RoundToBase(int a, int b)
        {
            return((int)Math2.RoundToBase((double)a, b));
        }
Beispiel #11
0
 /// <summary>
 /// Convert value to a string representation and constain to a unit radian
 /// </summary>
 /// <param name="radians"></param>
 /// <param name="significantDigits"></param>
 /// <returns></returns>
 static public string RadiansToString(double radians, int significantDigits)
 {
     return(Math2.ToString(ToUnitRadian(radians) / Math2.PI, significantDigits) + "PI");
 }
Beispiel #12
0
 /// <summary>
 /// Convert value to a string representation and constain to a unit radian
 /// </summary>
 /// <param name="radians"></param>
 /// <returns></returns>
 static public string RadiansToString(double radians)
 {
     return((Math2.ToUnitRadian(radians) / Math2.PI).ToString() + "PI");
 }