GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::ldexp,std::ldexpf,std::ldexpl(3) C++ Standard Libary std::ldexp,std::ldexpf,std::ldexpl(3)

std::ldexp,std::ldexpf,std::ldexpl - std::ldexp,std::ldexpf,std::ldexpl


Defined in header <cmath>
float ldexp ( float x, int exp ); (1) (constexpr since C++23)
float ldexpf( float x, int exp ); (2) (since C++11)
(constexpr since C++23)
double ldexp ( double x, int exp ); (3) (constexpr since C++23)
long double ldexp ( long double x, int exp ); (4) (constexpr since C++23)
long double ldexpl( long double x, int exp ); (5) (since C++11)
(constexpr since C++23)
double ldexp ( IntegralType x, int exp ); (6) (since C++11)
(constexpr since C++23)


1-5) Multiplies a floating point value x by the number 2 raised to the exp power.
6) A set of overloads or a function template accepting an argument of any integral
type. Equivalent to (3) (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


#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <cfenv>


// #pragma STDC FENV_ACCESS ON
int main()
{
std::cout << "ldexp(7, -4) = " << std::ldexp(7, -4) << '\n'
<< "ldexp(1, -1074) = " << std::ldexp(1, -1074)
<< " (minimum positive subnormal double)\n"
<< "ldexp(nextafter(1,0), 1024) = "
<< std::ldexp(std::nextafter(1,0), 1024)
<< " (largest finite double)\n";
// special values
std::cout << "ldexp(-0, 10) = " << std::ldexp(-0.0, 10) << '\n'
<< "ldexp(-Inf, -1) = " << std::ldexp(-INFINITY, -1) << '\n';
// error handling
errno = 0;
std::feclearexcept(FE_ALL_EXCEPT);
std::cout << "ldexp(1, 1024) = " << std::ldexp(1, 1024) << '\n';
if (errno == ERANGE)
std::cout << " errno == ERANGE: " << std::strerror(errno) << '\n';
if (std::fetestexcept(FE_OVERFLOW))
std::cout << " FE_OVERFLOW raised\n";
}


ldexp(7, -4) = 0.4375
ldexp(1, -1074) = 4.94066e-324 (minimum positive subnormal double)
ldexp(nextafter(1,0), 1024) = 1.79769e+308 (largest finite double)
ldexp(-0, 10) = -0
ldexp(-Inf, -1) = -inf
ldexp(1, 1024) = inf
errno == ERANGE: Numerical result out of range
FE_OVERFLOW raised


frexp
frexpf decomposes a number into significand and a power of 2
frexpl (function)
(C++11)
(C++11)
scalbn
scalbnf
scalbnl
scalbln
scalblnf
scalblnl multiplies a number by FLT_RADIX raised to a power
(C++11) (function)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.