C++ cmath scalbn() Function
Example
Multiply numbers by a power of 2:
cout << scalbn(1.5, 3) << "\n";
cout << 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 <cmath> header file.
Syntax
scalbn(double x, int y)
The function also works with float and long double values. Then it returns a value of the same type.
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 Math Tutorial.