How to workaround the inconsistent definition of numeric_limits::min()?

前端 未结 7 774
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 23:50

The numeric_limits traits is supposed to be a general way of obtaining various type infomation, to be able to do things like

template
T min(con         


        
相关标签:
7条回答
  • 2021-02-08 00:52

    A workaround would be

    double val = -std::numeric_limits<double>::max();
    

    Of course, this doesn't explain the strange behaviour of numerics_limits::min() which could be a result of the fact that there are different min/max borders for integers (min = -2^n, max = 2^n-1) but not for doubles.

    0 讨论(0)
提交回复
热议问题