Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

numeric_limits lowest and min member functions

numeric_limits<T>::min();
numeric_limits<T>::lowest();

What is the different between the value returned by both functions?

like image 872
Muhammad Avatar asked Apr 03 '13 09:04

Muhammad


People also ask

What does Numeric_limits do in C++?

The std::numeric_limits ::digits function is used to find the number of radix digits that the data type can represent without loss of precision.

Which of the following data types is accepted by the Numeric_limits function?

Data types that supports std::numeric_limits() in C++ std::numeric_limits<int>::max() gives the maximum possible value we can store in type int. std::numeric_limits<unsigned int>::max()) gives the maximum possible value we can store in type unsigned int.

Why is Denorm_min used?

This function is used to find the smallest non-zero denormalized value. Parameter: The function std::numeric_limits<T>::denorm_min() does not accept any parameter. Return Value: The functionstd::numeric_limits<T>::denorm_min() returns the smallest nonzero denormalized value of data type T.


2 Answers

Paragraph 18.3.2.4 of the C++11 Standard specifies:

static constexpr T min() noexcept;

1 Minimum finite value.

2 For floating types with denormalization, returns the minimum positive normalized value.

3 Meaningful for all specializations

[...]

static constexpr T lowest() noexcept;

6 A finite value x such that there is no other finite value y where y < x.

7 Meaningful for all specializations in which is_bounded != false.

Footnote 197 then adds the relevant remark:

lowest() is necessary because not all floating-point representations have a smallest (most negative) value that is the negative of the largest (most positive) finite value.

like image 119
Andy Prowl Avatar answered Oct 07 '22 17:10

Andy Prowl


For floating point types min returns the smallest finite number that is > 0 representable in the type (i.e. the number having the lowest absolute value != 0) while lowest returns the smallest finite number that is representable (i.e. the negative number of maximal absolute value that is less than -infinity).

like image 29
filmor Avatar answered Oct 07 '22 17:10

filmor