Click or drag to resize
mathilogb Method (Single)
Gets the unbiased exponent of the specified floating-point number.

Namespace:  C
Assembly:  C.math (in C.math.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static int ilogb(
	float number
)

Parameters

number
Type: SystemSingle
A floating-point number.

Return Value

Type: Int32
The unbiased exponent of the specified floating-point number, or a special value if number is not normal or subnormal.
Remarks

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(Single) is always 1 less than the exponent retuned by frexp(Single, Int32) because of the different normalization requirements: for ilogb(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 ilogb in the C standard documentation.

Examples
Assert.IsTrue(math.ilogb(1F) == 0);
Assert.IsTrue(math.ilogb((float)System.Math.E) == 1);
Assert.IsTrue(math.ilogb(1024F) == 10);
Assert.IsTrue(math.ilogb(-2000F) == 10);

Assert.IsTrue(math.ilogb(2F) == 1);
Assert.IsTrue(math.ilogb((float)Math.Pow(2F, 56F)) == 56);
Assert.IsTrue(math.ilogb(1.1F * (float)Math.Pow(2F, -149F)) == -149);
Assert.IsTrue(math.ilogb((float)Math.Pow(2F, -150F)) == math.FP_ILOGB0);
Assert.IsTrue(math.ilogb((float)Math.Pow(2F, 128F)) == math.INT_MAX);
Assert.IsTrue(math.ilogb((float)Math.Pow(2D, 127F)) == 127);
Assert.IsTrue(math.ilogb(2F * (float)Math.Pow(2F, 102F)) == 103);

Assert.IsTrue(math.ilogb(math.FLT_DENORM_MIN) == math.FLT_EXP_MIN - math.FLT_MANT_BITS);
Assert.IsTrue(math.ilogb(math.FLT_DENORM_MAX) == math.FLT_EXP_MIN - 1);
Assert.IsTrue(math.ilogb(math.FLT_MIN) == math.FLT_EXP_MIN);
Assert.IsTrue(math.ilogb(math.FLT_MAX) == math.FLT_EXP_MAX);

Assert.IsTrue(math.ilogb(System.Single.PositiveInfinity) == math.INT_MAX);
Assert.IsTrue(math.ilogb(System.Single.NegativeInfinity) == math.INT_MAX);
Assert.IsTrue(math.ilogb(0F) == math.FP_ILOGB0);
Assert.IsTrue(math.ilogb(-0F) == math.FP_ILOGB0);
Assert.IsTrue(math.ilogb(System.Single.NaN) == math.FP_ILOGBNAN);
Assert.IsTrue(math.ilogb(-System.Single.NaN) == math.FP_ILOGBNAN);
See Also