C Math scalbn() Function
Example
Multiply numbers by a power of 2:
printf("%f\n", scalbn(1.5, 3));
printf("%f", scalbn(6.0, -2));
Definition and Usage
The scalbn() function returns x multiplied by FLT_RADIX to the power of y. FLT_RADIX is the base that the computer uses to store decimal numbers. It is 2 on almost all computers.
In the example, scalbn(1.5, 3) is 1.5 * 2 * 2 * 2, which is 12. With 2 as the base, scalbn() does the same as ldexp().
The scalbn() function is defined in the <math.h> header file.
Syntax
double scalbn(double x, int y);
There are also versions for float and long double values: scalbnf() and scalbnl().
Parameter Values
| Parameter | Description |
|---|---|
| x | Required. The number to multiply. |
| y | Required. An int with the power to use. A negative value divides instead. |
Technical Details
| Returns: | A double value with the result. |
|---|
Related Pages
Read more about math in our C Math Tutorial.