Click or drag to resize
mathlogb Method (Double)
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 double logb(
	double number
)

Parameters

number
Type: SystemDouble
A floating-point number.

Return Value

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

Examples
Assert.IsTrue(math.logb(1D) == 0D);
Assert.IsTrue(math.logb(System.Math.E) == 1D);
Assert.IsTrue(math.logb(1024D) == 10D);
Assert.IsTrue(math.logb(-2000D) == 10D);

Assert.IsTrue(math.logb(2D) == 1D);
Assert.IsTrue(math.logb(Math.Pow(2D, 56D)) == 56D);
Assert.IsTrue(math.logb(1.1D * Math.Pow(2D, -1074D)) == -1074D);
Assert.IsTrue(math.logb(Math.Pow(2D, -1075D)) == System.Double.NegativeInfinity);
Assert.IsTrue(math.logb(Math.Pow(2D, 1024D)) == System.Double.PositiveInfinity);
Assert.IsTrue(math.logb(Math.Pow(2D, 1023D)) == 1023D);
Assert.IsTrue(math.logb(2D * Math.Pow(2D, 102D)) == 103D);

Assert.IsTrue(math.logb(math.DBL_DENORM_MIN) == math.DBL_EXP_MIN - math.DBL_MANT_BITS);
Assert.IsTrue(math.logb(math.DBL_DENORM_MAX) == math.DBL_EXP_MIN - 1);
Assert.IsTrue(math.logb(math.DBL_MIN) == math.DBL_EXP_MIN);
Assert.IsTrue(math.logb(math.DBL_MAX) == math.DBL_EXP_MAX);

Assert.IsTrue(math.logb(System.Double.PositiveInfinity) == System.Double.PositiveInfinity);
Assert.IsTrue(math.logb(System.Double.NegativeInfinity) == System.Double.PositiveInfinity);
Assert.IsTrue(math.logb(0D) == System.Double.NegativeInfinity);
Assert.IsTrue(math.logb(-0D) == System.Double.NegativeInfinity);
Assert.IsTrue(System.Double.IsNaN(math.logb(System.Double.NaN)));
Assert.IsTrue(System.Double.IsNaN(math.logb(-System.Double.NaN)));
See Also