std::ldexp,std::ldexpf,std::ldexpl (3) - Linux Manuals
Defined in header <cmath>
float ldexp ( float x, int exp );
float ldexpf( float x, int exp ); (since C++11)
double ldexp ( double x, int exp ); (1) (2)
long double ldexp ( long double x, int exp );
long double ldexpl( long double x, int exp ); (3) (since C++11)
double ldexp ( IntegralType x, int exp ); (4) (since C++11)
1-3) Multiplies a floating point value x by the number 2 raised to the exp power.
4) A set of overloads or a function template accepting an argument of any integral_type. Equivalent to (2) (the argument is cast to double).
x - floating point value
exp - integer value
If no errors occur, x multiplied by 2 to the power of exp (x×2exp
) is returned.
If a range error due to overflow occurs, ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL is returned.
If a range error due to underflow occurs, the correct result (after rounding) is returned.
Errors are reported as specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
* Unless a range error occurs, FE_INEXACT is never raised (the result is exact)
* Unless a range error occurs, the_current_rounding_mode is ignored
* If x is ±0, it is returned, unmodified
* If x is ±∞, it is returned, unmodified
* If exp is 0, then x is returned, unmodified
* If x is NaN, NaN is returned
On binary systems (where FLT_RADIX is 2), std::ldexp is equivalent to std::scalbn.
The function std::ldexp ("load exponent"), together with its dual, std::frexp, can be used to manipulate the representation of a floating-point number without direct bit manipulations.
On many implementations, std::ldexp is less efficient than multiplication or division by a power of two using arithmetic operators.
// Run this code
frexpl decomposes a number into significand and a power of 2
scalblnl multiplies a number by FLT_RADIX raised to a power