mathilogb Method (Double) |
Namespace: C
The unbiased exponent is the integral part of the logarithm base 2 of number. The unbiased exponent is such that:
number = significand(number) * 2^ilogb(number).
The return unbiased exponent is valid for all normal and subnormal numbers. Special values are treated as follows.
If number is not zero, infinite, or NaN, the value returned is exactly equivalent to (Int32)logb(number).
The value of the exponent returned by ilogb(Double) is always 1 less than the exponent retuned by frexp(Double, Int32) because of the different normalization requirements: for ilogb(Double), the normalized significand is in the interval [1, 2), but for frexp(Double, Int32), the normalized significand is in the interval [0.5, 1).
See ilogb in the C standard documentation.
Assert.IsTrue(math.ilogb(1D) == 0); Assert.IsTrue(math.ilogb(System.Math.E) == 1); Assert.IsTrue(math.ilogb(1024D) == 10); Assert.IsTrue(math.ilogb(-2000D) == 10); Assert.IsTrue(math.ilogb(2D) == 1); Assert.IsTrue(math.ilogb(Math.Pow(2D, 56D)) == 56); Assert.IsTrue(math.ilogb(1.1D * Math.Pow(2D, -1074D)) == -1074); Assert.IsTrue(math.ilogb(Math.Pow(2D, -1075D)) == math.FP_ILOGB0); Assert.IsTrue(math.ilogb(Math.Pow(2D, 1024D)) == math.INT_MAX); Assert.IsTrue(math.ilogb(Math.Pow(2D, 1023D)) == 1023); Assert.IsTrue(math.ilogb(2D * Math.Pow(2D, 102D)) == 103); Assert.IsTrue(math.ilogb(math.DBL_DENORM_MIN) == math.DBL_EXP_MIN - math.DBL_MANT_BITS); Assert.IsTrue(math.ilogb(math.DBL_DENORM_MAX) == math.DBL_EXP_MIN - 1); Assert.IsTrue(math.ilogb(math.DBL_MIN) == math.DBL_EXP_MIN); Assert.IsTrue(math.ilogb(math.DBL_MAX) == math.DBL_EXP_MAX); Assert.IsTrue(math.ilogb(System.Double.PositiveInfinity) == math.INT_MAX); Assert.IsTrue(math.ilogb(System.Double.NegativeInfinity) == math.INT_MAX); Assert.IsTrue(math.ilogb(0D) == math.FP_ILOGB0); Assert.IsTrue(math.ilogb(-0D) == math.FP_ILOGB0); Assert.IsTrue(math.ilogb(System.Double.NaN) == math.FP_ILOGBNAN); Assert.IsTrue(math.ilogb(-System.Double.NaN) == math.FP_ILOGBNAN);