Std :: numeric_limits <T> :: epsilon () for integrals

I do not have good links to std::numeric_limits<T> , but sites on the net say that std::numeric_limits<T>::epsilon() will return the difference between 1 and the smallest number after it. As far as I know about int , the next number after 1 is 2 , so epsilon should be 1 . But it is 0 (Linux, g ++ 4.4.5). What are the reasons for this?

I know that in practice epsilon() is only useful for floating point types, I'm just nitpicking.

+6
source share
2 answers

The standard says ([numeric.limits.members])

The value for all floating point types.

The standard also says ([numerical. Special])

many values ​​should be meaningful only under certain conditions (e.g. epsilon () only makes sense if is_integer is false). Any value that is not “significant” must be 0 or false.

Since the value is not “significant”, a value of 0 is required by the standard as an indication that it is not a significant value.

+8
source

I would say that it returns a range for which numbers are considered equal, with integer types whose range must be 0.

Those. if you are creating generic functions that can handle both integer and floating point types, you need a range for integers.

+2
source

Source: https://habr.com/ru/post/924613/


All Articles