Click or drag to resize
mathscalbn Method (Single, Int32)
Scales the specified floating-point number by 2^exponent.

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

Parameters

number
Type: SystemSingle
A floating-point number.
exponent
Type: SystemInt32
The exponent of the power of two.

Return Value

Type: Single
The value number * 2^exponent.
Remarks

Special values are treated as follows.

  • If number is ±0, it is returned.
  • If number is infinite, it is returned.
  • If exponent is 0, number is returned.
  • If number is NaN, NaN is returned.

The function scalbn(Single, Int32) is equivalent to ldexp(Single, Int32).

See scalbn in the C standard documentation.

Examples
Assert.IsTrue(math.scalbn(0.8F, 4) == 12.8F);
Assert.IsTrue(math.scalbn(-0.854375F, 5) == -27.34F);
Assert.IsTrue(math.scalbn(1F, 0) == 1F);

Assert.IsTrue(math.scalbn(math.FLT_MIN / 2F, 0) == math.FLT_MIN / 2F);
Assert.IsTrue(math.scalbn(math.FLT_MIN / 2F, 1) == math.FLT_MIN);
Assert.IsTrue(math.scalbn(math.FLT_MIN * 1.5F, -math.FLT_MANT_BITS) == 2F * math.FLT_DENORM_MIN);
Assert.IsTrue(math.scalbn(math.FLT_MIN * 1.5F, -math.FLT_MANT_BITS - 1) == math.FLT_DENORM_MIN);
Assert.IsTrue(math.scalbn(math.FLT_MIN * 1.25F, -math.FLT_MANT_BITS) == math.FLT_DENORM_MIN);
Assert.IsTrue(math.scalbn(math.FLT_MIN * 1.25F, -math.FLT_MANT_BITS - 1) == math.FLT_DENORM_MIN);

Assert.IsTrue(math.scalbn(1F, System.Int32.MaxValue) == System.Single.PositiveInfinity);
Assert.IsTrue(math.scalbn(1F, System.Int32.MinValue) == 0F);
Assert.IsTrue(math.scalbn(-1F, System.Int32.MaxValue) == System.Single.NegativeInfinity);
Assert.IsTrue(math.scalbn(-1F, System.Int32.MinValue) == -0F);
See Also