mathlogb Method (Single) |
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^logb(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 ilogb(number).
The value of the exponent returned by logb(Single) is always 1 less than the exponent retuned by frexp(Single, Int32) because of the different normalization requirements: for logb(Single), the normalized significand is in the interval [1, 2), but for frexp(Single, Int32), the normalized significand is in the interval [0.5, 1).
See logb in the C standard documentation.
Assert.IsTrue(math.logb(1F) == 0F); Assert.IsTrue(math.logb((float)System.Math.E) == 1F); Assert.IsTrue(math.logb(1024F) == 10F); Assert.IsTrue(math.logb(-2000F) == 10F); Assert.IsTrue(math.logb(2F) == 1F); Assert.IsTrue(math.logb((float)Math.Pow(2F, 56F)) == 56F); Assert.IsTrue(math.logb(1.1F * (float)Math.Pow(2F, -149F)) == -149F); Assert.IsTrue(math.logb((float)Math.Pow(2F, -150F)) == System.Single.NegativeInfinity); Assert.IsTrue(math.logb((float)Math.Pow(2F, 128F)) == System.Single.PositiveInfinity); Assert.IsTrue(math.logb((float)Math.Pow(2D, 127F)) == 127F); Assert.IsTrue(math.logb(2F * (float)Math.Pow(2F, 102F)) == 103F); Assert.IsTrue(math.logb(math.FLT_DENORM_MIN) == math.FLT_EXP_MIN - math.FLT_MANT_BITS); Assert.IsTrue(math.logb(math.FLT_DENORM_MAX) == math.FLT_EXP_MIN - 1); Assert.IsTrue(math.logb(math.FLT_MIN) == math.FLT_EXP_MIN); Assert.IsTrue(math.logb(math.FLT_MAX) == math.FLT_EXP_MAX); Assert.IsTrue(math.logb(System.Single.PositiveInfinity) == System.Single.PositiveInfinity); Assert.IsTrue(math.logb(System.Single.NegativeInfinity) == System.Single.PositiveInfinity); Assert.IsTrue(math.logb(0F) == System.Single.NegativeInfinity); Assert.IsTrue(math.logb(-0F) == System.Single.NegativeInfinity); Assert.IsTrue(System.Single.IsNaN(math.logb(System.Single.NaN))); Assert.IsTrue(System.Single.IsNaN(math.logb(-System.Single.NaN)));