A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../error/error_code/../../../cpp/numeric/math/logb.html below:

std::logb, std::logbf, std::logbl - cppreference.com

(1) float       logb ( float num );

double      logb ( double num );

long double logb ( long double num );
(until C++23)

constexpr /*floating-point-type*/
            logb ( /*floating-point-type*/ num );

(since C++23)

float       logbf( float num );

(2) (since C++11)
(constexpr since C++23)

long double logbl( long double num );

(3) (since C++11)
(constexpr since C++23) template< /*math-floating-point*/ V >

constexpr /*deduced-simd-t*/<V>

            logb ( const V& v_num );
(S) (since C++26)

template< class Integer >
double      logb ( Integer num );

(A) (constexpr since C++23)

1-3) Extracts the value of the unbiased radix-independent exponent from the floating-point argument num, and returns it as a floating-point value. The library provides overloads of std::logb for all cv-unqualified floating-point types as the type of the parameter.(since C++23)

A) Additional overloads are provided for all integer types, which are treated as double.

(since C++11)

Formally, the unbiased exponent is the signed integral part of logr|num| (returned by this function as a floating-point value), for non-zero num, where r is std::numeric_limits<T>::radix and T is the floating-point type of num. If num is subnormal, it is treated as though it was normalized.

[edit] Parameters num - floating-point or integer value [edit] Return value

If no errors occur, the unbiased exponent of num is returned as a signed floating-point value.

If a domain error occurs, an implementation-defined value is returned.

If a pole error occurs, -HUGE_VAL, -HUGE_VALF, or -HUGE_VALL is returned.

[edit] Error handling

Errors are reported as specified in math_errhandling.

Domain or range error may occur if num is zero.

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

[edit] Notes

POSIX requires that a pole error occurs if num is ±0.

The value of the exponent returned by std::logb is always 1 less than the exponent returned by std::frexp because of the different normalization requirements: for the exponent e returned by std::logb, |num*r-e
|
is between 1 and r (typically between 1 and 2), but for the exponent e returned by std::frexp, |num*2-e
|
is between 0.5 and 1.

The additional overloads are not required to be provided exactly as (A). They only need to be sufficient to ensure that for their argument num of integer type, std::logb(num) has the same effect as std::logb(static_cast<double>(num)).

[edit] Example

Compares different floating-point decomposition functions:

Possible output:

Given the number 123.45 or 0x1.edccccccccccdp+6 in hex,
modf() makes 123 + 0.45
frexp() makes 0.964453 * 2^7
logb()/ilogb() make 1.92891 * 2^6
logb(0) = -Inf
    FE_DIVBYZERO raised
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4