示例#1
0
        public static float Log(float value, float newBase)
        {
            if (value < 0.0f ||
                newBase < 0.0f ||
                (value != 1.0f && newBase == 0.0f) ||
                (value != 1.0f && newBase == float.PositiveInfinity) ||
                XMath.IsNaN(value) ||
                XMath.IsNaN(newBase) ||
                newBase == 1.0f)
            {
                return(float.NaN);
            }

            if (value == 0.0f)
            {
                if (0.0f < newBase && newBase < 1.0f)
                {
                    return(float.PositiveInfinity);
                }
                else if (newBase > 1.0f)
                {
                    return(float.NegativeInfinity);
                }
            }

            if (value == float.PositiveInfinity)
            {
                if (0.0f < newBase && newBase < 1.0f)
                {
                    return(float.NegativeInfinity);
                }
                else if (newBase > 1.0f)
                {
                    return(float.PositiveInfinity);
                }
            }

            if (value == 1.0f && (newBase == 0.0f || newBase == float.PositiveInfinity))
            {
                return(0.0f);
            }

            return(XMath.Log(value) * XMath.Rcp(XMath.Log(newBase)));
        }
示例#2
0
        public static double Log(double value, double newBase)
        {
            if (value < 0.0 ||
                newBase < 0.0 ||
                (value != 1.0 && newBase == 0.0) ||
                (value != 1.0 && newBase == double.PositiveInfinity) ||
                XMath.IsNaN(value) ||
                XMath.IsNaN(newBase) ||
                newBase == 1.0)
            {
                return(double.NaN);
            }

            if (value == 0.0)
            {
                if (0.0 < newBase && newBase < 1.0)
                {
                    return(double.PositiveInfinity);
                }
                else if (newBase > 1.0)
                {
                    return(double.NegativeInfinity);
                }
            }

            if (value == double.PositiveInfinity)
            {
                if (0.0 < newBase && newBase < 1.0)
                {
                    return(double.NegativeInfinity);
                }
                else if (newBase > 1.0)
                {
                    return(double.PositiveInfinity);
                }
            }

            if (value == 1.0 && (newBase == 0.0 || newBase == double.PositiveInfinity))
            {
                return(0.0);
            }

            return(XMath.Log(value) * XMath.Rcp(XMath.Log(newBase)));
        }
示例#3
0
 public static float Log10(float value) =>
 XMath.Log(value) * XMath.OneOverLn10;
示例#4
0
 static double Log(double x) => XMath.Log((float)x);