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

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

Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
Muhammad
  • 1,598
  • 3
  • 19
  • 31
  • 3
    [For future readers], the table at https://en.cppreference.com/w/cpp/types/numeric_limits, explains it quite well. – dvlper May 20 '20 at 01:59

3 Answers3

26

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.

Community
  • 1
  • 1
Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
14

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).

filmor
  • 30,840
  • 6
  • 50
  • 48
  • 3
    The smallest number that is representable is negative infinity; `lowest` give the smallest **finite** representable value. – Pete Becker Apr 03 '13 at 13:29
0

If you check a reference of these functions, e.g. this one for min and this one for lowest you can see that there are some values that differ.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621